JSoup parsing invalid HTML with unclosed tags

html-parsing, java, jsoup, web-crawler

Solution

The correct behavior is to act as other browsers when parsing this invalid HTML. Thanks for filing this bug. I've fixed the issue that was preventing the adoption agency from keeping the original attributes in the new node. It will be available in 1.7.3, or you can build from head now.

Problem

Using JSoup inclusive the last release 1.7.2 there is a bug parsing invalid HTML with unclosed tags. Example: ``` String tmp = "<a href='www.google.com'>Link<p>Error link</a>"; Jsoup.parse(tmp); ``` The Document that generate is: ``` <html> <head></head> <body> <a href="www.google.com">Link</a> <p><a>Error link</a></p> </body> </html> ``` The browsers would generate something as: ``` <html> <head></head> <body> <a href="www.google.com">Link</a> <p><a href="www.google.com">Error link</a></p> </body> </html> ``` Jsoup should works as browsers or as source code. There is any solution? Looking into the API I didn't find anything.

Original source