If we run the the following HTML through HTMLCleaner:
<a href="https://www.moneysavingexpert.com/car-insurance/"><br> <h3>Compare cheap car insurance quotes online - MSE</h3> <div> <cite>www.moneysavingexpert.com › car-insurance</cite> </div> </a>
We get the following:
<a href="https://www.moneysavingexpert.com/car-insurance/"> <h3> Compare cheap car insurance quotes online - MSE <div> <cite>www.moneysavingexpert.com › car-insurance</cite> </div> </h3> <br/> </a>
Note how is incorreclty placed after
Thanks Daniel, I'll check it out.
OK, the culprit is the
xmlns='foo'
attribute in the root element. This basically switches the parser from reading HTML elements to reading elements as being 'foreign markup'. So because of this it doesn't apply the rules that put the H3 and DIV in the correct nesting when it moves out the unclosed BR tag (again, because it thinks this is now a foo:BR tag it doesn't know its a HTML BR tag so doesn't auto-close it). If you remove the xmlns attribute, or set it to the XHTML namespace such as 'http://www.w3.org/1999/xhtml', then it all behaves properly.Does this problem occur in any 'real' HTML or is it just a test case?
Hi Scott,
Thanks for your response.
Yes this problem occurred in real HTML.
The following HTML will reproduce it:
Seems that the
Thanks
Danny
Hi Scott,
Seems that sourceforge is removing some of my comments if I refer to html tags.
What I wanted to say is that I believe it is the svg tags that is causing the issue in the above example.
Thanks
Danny
Got it. I think the problem here is specifically the lenient processing of SVG tags, where we use an 'implied namespace' to include them in HTML. Looks like this namespace doesn't get 'turned off' when the SVG element is closed.
Adding a check to pop the 'implied namespace' to htmlcleaner.makeTree seems to fix it:
I'll need to run a few more tests to make sure this is 'safe', but it looks like it may do the trick.
Committed - this will be in the next release.
Hi Scott,
I have been working with Danny on this bug internally.
After updating to v2.24, we still seem to get the same incorrect output for the Java file
HTMLCleanerBug.java
attached to the original post. Could you please take a look?Remi
Hi Remi,
Remove the "xmlns='foo'" attribute, as this effectively tells HC "this is not HTML".
Hi Scott,
Thanks for clarifying - everything seems to work alright now.
Remi
That's great! I'm glad I could help.
There is a stray escaped quote in the H3 tag name - I'm assuming this is what you are testing for. HC will pick this up and clean it if it thinks this is a HTML tag and not 'foreign markup'.