Java Code Examples for org.owasp.encoder.Encode#forJavaScript()

The following examples show how to use org.owasp.encoder.Encode#forJavaScript() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SanitizerHandlerTest.java    From light-4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncoder() throws Exception {
    String s1 = "keep-alive";
    String s2 = "text/html";
    Assert.assertEquals(Encode.forJavaScriptSource(s1), s1);
    Assert.assertEquals(Encode.forJavaScriptSource(s2), s2);

    String s3 = "<script>alert('test')</script>";
    String e3 = Encode.forJavaScriptSource(s3);
    System.out.println("source = " + e3);
    String e4 = Encode.forJavaScriptAttribute(s3);
    System.out.println("attribute = " + e4);
    String e5 = Encode.forJavaScriptBlock(s3);
    System.out.println("block = " + e5);
    String e6 = Encode.forJavaScript(e3);
    System.out.println("script = " + e6);
    Assert.assertNotEquals(e3, s3);

    String s7 = "<script>location.href=\"respources.html\"</script>";
    String e7 = Encode.forJavaScriptSource(s7);
    System.out.println("e7 = " + e7);
}
 
Example 2
Source File: EncoderTest.java    From light-4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testForJavaScript() {
    String result = Encode.forJavaScript(s);
    System.out.println("JavaScript: " + result);
}
 
Example 3
Source File: ForJavaScriptTag.java    From owasp-java-encoder with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {
    Encode.forJavaScript(getJspContext().getOut(), _value);
}
 
Example 4
Source File: ESAPIEncoder.java    From owasp-java-encoder with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** {@inheritDoc} */
public String encodeForJavaScript(String s) {
    return Encode.forJavaScript(s);
}
 
Example 5
Source File: EncodeHostObject.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public static String jsFunction_forJavaScript(Context cx, Scriptable thisObj, Object[] args, Function funObj)
        throws APIManagementException{
    return Encode.forJavaScript(validateInput(args));
}