Open rasmitam opened 4 years ago
I think setNestingLimit is what you want.
I think setNestingLimit is what you want.
Correct me if I'm wrong, but there doesn't seem to be a way to change this with the public API.
setNestingLimit
is called on an instance of TagBalancingHtmlStreamEventReceiver
that is constructed inside of the implementation of HtmlSanitizer#sanitize
, so there is no way to access that TagBalancingHtmlStreamEventReceiver
.
One could try to reimplement their own version of HtmlSanitizer#sanitize
. However, that method relies on the HtmlLexer
class, which is not public, so there is no way to access HtmlLexer
without reflection.
@jacobrshields IIRC, the lexer is invoked by Sanitizer.sanitize which you can supply with a policy that chains together the balancer with other bits and bobs if you're so inclined.
Some of the example code sets up custom pipelines:
@mikesamuel I'm not sure I'm following completely.
You can configure your policy with your own HtmlStreamEventReceiver
, and you can specify your own HtmlStreamEventProcessor
when you call HtmlSanitizer#sanitize
, but ultimately a TagBalancingHtmlStreamEventReceiver
with a nesting limit of 256
is hard-coded to be wrapped around any preprocessor you pass in:
Are you saying you could define an HtmlStreamEventReceiver
or an HtmlStreamEventProcessor
such that they hack around the hard-coded TagBalancingHtmlStreamEventReceiver
? It's not clear to me how one would accomplish this.
In Zimbra we have also faced the same issue, so fixed up by ramping it's value: https://github.com/Zimbra/java-html-sanitizer-release-20190610.1/commit/bc58f5843b0f5d05d89e94ccd146f21aeb18df81
I
have a HTML which is surrounded by a big list of empty<div>
tags, sanitizer is removing a portion of a HTML. When removed the empty list of<div>
tags from the HTML the sanitizer did not strip off the portion of the HTML. Please find the HTML where the issue is seen. Please suggest what can be done for this issue.Post sanitization
Post sanitization: After Rasmita06 all other divs are removed.
What I did next is removed the unwanted divs from the top and also removed the closing divs and see the results below.
post Sanitization:
See here post Rasmita06 all other divs are not removed.
Sample_html.txt Added the html causing issue to the bug.