How to prevent JSoup cleaner tampering the content

。_饼干妹妹 提交于 2021-02-08 09:28:49

问题


I need JSoup to remove scripts from some HTML string, and using this snippet for that:

Document unsafeDoc = Jsoup.parse(unsafeHtml);
Document safeDoc = cleaner.clean(unsafeDoc);
OutputSettings o = safeDoc.outputSettings();
o.escapeMode(EscapeMode.xhtml);
return safeDoc.select("body").html();

But it is inserting extra space before <br> tags, converting " and ' to &quot; and &apos; etc., which I don't want. Could not find a way to achieve this. Would appreciate any help or recommendations of any other library than JSoup doing this.

Thanks, Sanjay


回答1:


Try using:

safeDoc.outputSettings().prettyPrint(false);

I had the same problem and that fixed it.



来源:https://stackoverflow.com/questions/11288324/how-to-prevent-jsoup-cleaner-tampering-the-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!