【问题标题】:Not able to encode , (comma) _(underscore) -(hyphen) using ESAPI encodeforXML method无法使用 ESAPI encodeforXML 方法对 , (comma) _(underscore) -(hyphen) 进行编码
【发布时间】:2020-11-27 07:18:45
【问题描述】:

在下面的代码中,我尝试对特殊字符进行编码

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, _ - & () %

是否有一些设置需要编码,_ -?谢谢。

【问题讨论】:

    标签: java owasp encoder esapi xmlencoder


    【解决方案1】:

    在 XML 中,没有必要对下划线字符进行编码。见https://www.w3.org/TR/xml/#charencoding

    只有以下字符需要转义:https://www.w3.org/TR/REC-xml/#dt-escape

    【讨论】:

      猜你喜欢
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多