java 某个目录白名单_java – 如何使Jsoup白名单接受某些属性内容

您可以扩展白名单并覆盖

isSafeAttribute以执行自定义检查.由于无法直接扩展Whitelist.relaxed(),您必须复制一些代码来设置相同的列表:

public class RelaxedPlusDataBase64Images extends Whitelist {

public RelaxedPlusDataBase64Images() {

//copied from Whitelist.relaxed()

addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col",

"colgroup", "dd", "div", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5", "h6",

"i", "img", "li", "ol", "p", "pre", "q", "small", "strike", "strong",

"sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "u",

"ul");

addAttributes("a", "href", "title");

addAttributes("blockquote", "cite");

addAttributes("col", "span", "width");

addAttributes("colgroup", "span", "width");

addAttributes("img", "align", "alt", "height", "src", "title", "width");

addAttributes("ol", "start", "type");

addAttributes("q", "cite");

addAttributes("table", "summary", "width");

addAttributes("td", "abbr", "axis", "colspan", "rowspan", "width");

addAttributes("th", "abbr", "axis", "colspan", "rowspan", "scope", "width");

addAttributes("ul", "type");

addProtocols("a", "href", "ftp", "http", "https", "mailto");

addProtocols("blockquote", "cite", "http", "https");

addProtocols("cite", "cite", "http", "https");

addProtocols("img", "src", "http", "https");

addProtocols("q", "cite", "http", "https");

}

@Override

protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {

return ("img".equals(tagName)

&& "src".equals(attr.getKey())

&& attr.getValue().startsWith("data:;base64")) ||

super.isSafeAttribute(tagName, el, attr);

}

}

由于您尚未提供用于解析的代码或正在清理的HTML,因此我没有对此进行测试.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值