如何配置jsoup Whitelist
以允許內部定位點引用,但不允許任何值?如何配置jsoup白名單以允許內部定位點
HTML示例:
<a href="#section1" target="_self">Jump To Section 1</a>
<!-- ... -->
<a name="section1">Section 1</a>
如果我試圖用輕鬆的Whitelist
的href
清潔代碼被刪除。
Jsoup.clean(html, Whitelist.relaxed().addAttributes("a", "name", "target");
返回如下:
<a target="_self">Jump To Section 1</a>
<!-- ... -->
<a name="section1">Section 1</a>
如果我手動建立一個Whitelist
並添加標籤和屬性,我想,但不叫addProtocols(....)
我能得到jsoup離開到位href
,但這看起來不是一個好的解決方案,因爲它不會過濾掉包含JavaScript的href
。例如,我想從下面取出一個標籤(或至少href
):
<a href="javascript:alert(1111);" target="_self">Jump To Section 1</a>
<a name="section1">Section 1</a>
這可能與jsoup?
我沒有看到下面的補丁提交jsoup,但它並不像它製作成的jsoup代碼庫:https://github.com/jhy/jsoup/pull/77