package com.wb.common;


import cn.hutool.http.HTMLFilter;
import com.ag.util.StrUtil;

public class XssEncode {
    public static String xssEncode(String s) {
        if (StrUtil.isEmpty(s)) {
            return s;
        }
        try {
            HTMLFilter htmlFilter = new HTMLFilter();
            String res = htmlFilter.filter(s).replace("&quot;", "\"").replaceAll("&amp;","&");
            if (StrUtil.equals(s, res)){
                return s;
            }else {
                throw new RuntimeException("发现非法字符："+s);
            }
        } catch (Exception e) {
            throw new RuntimeException("发现异常字符->"+s);
        }
    }

}