无法使用 ESAPI encodeforXML 方法对 ,(逗号)_(下划线)-(连字符)进行编码
Not able to encode , (comma) _(underscore) -(hyphen) using ESAPI encodeforXML method
在下面的代码中,我尝试对特殊字符进行编码
package hello;
//import java.io.UnsupportedEncodingException;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Encoder;
import org.owasp.esapi.errors.EncodingException;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("Hello Worldadndh");
// System.out.println("ESAPI.accessacController found: "
// + ESAPI.accessController());
String encodedString = encodeForXML("comma underscore hyphen, _ - & () %");
System.out.println("The encoded string is "+encodedString);
}
public static String encodeForXML(String str)
{
return ESAPI.encoder().encodeForXML(str);
}
}
o/p是
The encoded string is comma underscore hyphen, _ - & () %
编码 , _ - 是否需要一些设置?谢谢。
在XML中,不需要对下划线字符进行编码。参见 https://www.w3.org/TR/xml/#charencoding。
只有以下字符需要转义:https://www.w3.org/TR/REC-xml/#dt-escape.
在下面的代码中,我尝试对特殊字符进行编码
package hello;
//import java.io.UnsupportedEncodingException;
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Encoder;
import org.owasp.esapi.errors.EncodingException;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("Hello Worldadndh");
// System.out.println("ESAPI.accessacController found: "
// + ESAPI.accessController());
String encodedString = encodeForXML("comma underscore hyphen, _ - & () %");
System.out.println("The encoded string is "+encodedString);
}
public static String encodeForXML(String str)
{
return ESAPI.encoder().encodeForXML(str);
}
}
o/p是
The encoded string is comma underscore hyphen, _ - & () %
编码 , _ - 是否需要一些设置?谢谢。
在XML中,不需要对下划线字符进行编码。参见 https://www.w3.org/TR/xml/#charencoding。
只有以下字符需要转义:https://www.w3.org/TR/REC-xml/#dt-escape.