@Test public void testRemoveUnSafeTag() { String html = "<a onclick='alert(1)' onBlur='alert(1)'>你好</a><script>alert(1)</script><Script>alert(1)</SCRIPT>"; Assert.assertEquals("<a>你好</a>", HtmlUtils.removeUnSafeTag(html)); }
public static String removeUnSafeTag(String html) { SishuokWhitelist whitelist = new SishuokWhitelist(); whitelist.addTags("embed", "object", "param", "span", "div", "img", "font", "del"); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup"); whitelist.addTags("dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img"); whitelist.addTags("li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table"); whitelist.addTags("tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes(":all", "on"); Document dirty = Jsoup.parseBodyFragment(html, ""); SishuokCleaner cleaner = new SishuokCleaner(whitelist); Document clean = cleaner.clean(dirty); return clean.body().html(); }
HtmlUtils { public static String removeUnSafeTag(String html) { SishuokWhitelist whitelist = new SishuokWhitelist(); whitelist.addTags("embed", "object", "param", "span", "div", "img", "font", "del"); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup"); whitelist.addTags("dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img"); whitelist.addTags("li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table"); whitelist.addTags("tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes(":all", "on"); Document dirty = Jsoup.parseBodyFragment(html, ""); SishuokCleaner cleaner = new SishuokCleaner(whitelist); Document clean = cleaner.clean(dirty); return clean.body().html(); } }
HtmlUtils { public static String removeUnSafeTag(String html) { SishuokWhitelist whitelist = new SishuokWhitelist(); whitelist.addTags("embed", "object", "param", "span", "div", "img", "font", "del"); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup"); whitelist.addTags("dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img"); whitelist.addTags("li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table"); whitelist.addTags("tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes(":all", "on"); Document dirty = Jsoup.parseBodyFragment(html, ""); SishuokCleaner cleaner = new SishuokCleaner(whitelist); Document clean = cleaner.clean(dirty); return clean.body().html(); }  }
HtmlUtils { public static String removeUnSafeTag(String html) { SishuokWhitelist whitelist = new SishuokWhitelist(); whitelist.addTags("embed", "object", "param", "span", "div", "img", "font", "del"); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup"); whitelist.addTags("dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img"); whitelist.addTags("li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table"); whitelist.addTags("tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes(":all", "on"); Document dirty = Jsoup.parseBodyFragment(html, ""); SishuokCleaner cleaner = new SishuokCleaner(whitelist); Document clean = cleaner.clean(dirty); return clean.body().html(); }  static String text(String html); static String text(String html, int maxLength); static String removeUnSafeTag(String html); static String removeTag(String html, String tagName); }
HtmlUtils { public static String removeUnSafeTag(String html) { SishuokWhitelist whitelist = new SishuokWhitelist(); whitelist.addTags("embed", "object", "param", "span", "div", "img", "font", "del"); whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup"); whitelist.addTags("dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "img"); whitelist.addTags("li", "ol", "p", "pre", "q", "small", "strike", "strong", "sub", "sup", "table"); whitelist.addTags("tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul"); whitelist.addAttributes(":all", "on"); Document dirty = Jsoup.parseBodyFragment(html, ""); SishuokCleaner cleaner = new SishuokCleaner(whitelist); Document clean = cleaner.clean(dirty); return clean.body().html(); }  static String text(String html); static String text(String html, int maxLength); static String removeUnSafeTag(String html); static String removeTag(String html, String tagName);  }