Re: [Htmlparser-user] Endless recursion bug in toHtml() ?
Brought to you by:
derrickoswald
From: Bram <br...@av...> - 2006-04-13 08:13:37
|
Hello Derrick, > The mini <A/> tag in your test case is considered a content-less XML > tag (see isEmptyXmlTag() in TagNode). > This causes the parser to set the end tag reference to be the start tag > - this is done so that there will always be an end tag, which may be a > bad design decision, but it was thought to be better than inventing a > non-existent tag, or returning null. > > When you add an HREF attribute in this case, the only attribute (the tag > name with the slash) is no longer the last attribute and hence > isEmptyXmlTag returns false, but the end tag reference is still pointing > to the start tag, which causes the recursion. > Thanks for the explanation. > I guess the add attribute code could be smarter and detect this > pathological situation, but I'm wondering if that's the real solution or > just a band-aid. > That sounds like a band-aid indeed, but it's a viable solution to prevent this problem until something better has been worked out, IMHO. > Was this discovered in the wild? Why is the XML syntax used for an > empty link? Is this an XML file? Perhaps an XML parser would be a > better choice. > Apparently I over-simplified the problem I occasionally occur. I tried to use the exact same test case on the URL that gave me the problems, and now it worked flawlessly. After a bit of tinkering I noticed I changed the name of the attribute (from 'onclick' to 'href') while trying to isolate the problem yesterday. Changing it back to 'onclick' will fail the test. This can be explained by the fact that the broken <a> tag already had a 'href' attribute, and simply changing an existing attribute doesn't trigger the problem. This is demonstrated in the newly attached JUnit test. Sadly, '<a ... />' tags do occur in the wild, so it would be very good to prevent this from happing, from a user's point of view. Bram -- Light travels faster than sound. This is why some people appear bright until you hear them speak. |