本文整理汇总了Java中org.owasp.encoder.Encode.forJavaScript方法的典型用法代码示例。如果您正苦于以下问题:Java Encode.forJavaScript方法的具体用法?Java Encode.forJavaScript怎么用?Java Encode.forJavaScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.owasp.encoder.Encode
的用法示例。
在下文中一共展示了Encode.forJavaScript方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEncoder
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@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);
//Assert.assertEquals(Encode.forJavaScriptBlock(s1), s1);
//Assert.assertEquals(Encode.forJavaScriptBlock(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);
}
示例2: forJavascript
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
/**
* Encodes for a JavaScript string.
* <p>
* Safe for use in HTML script attributes (such as onclick), script blocks, JSON files, and JavaScript source.
*
* @param input Javascript input, may be null
*
* @return Encoded Javascript, empty string if anything goes wrong
*/
public String forJavascript( String input )
{
if( isEmpty( input ) )
{
return EMPTY;
}
try
{
return Encode.forJavaScript( input );
}
catch( Exception ex )
{
LOG.error( "Encoding for Javascript error, will return empty string: {}", ex.getMessage(), ex );
return EMPTY;
}
}
示例3: doTag
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
@Override
public void doTag() throws JspException, IOException {
Encode.forJavaScript(getJspContext().getOut(), _value);
}
示例4: encodeForJavaScript
import org.owasp.encoder.Encode; //导入方法依赖的package包/类
/** {@inheritDoc} */
public String encodeForJavaScript(String s) {
return Encode.forJavaScript(s);
}