From 5211ffe4df8ea41423c1a37635f7c1263a1db754 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Mon, 13 Feb 2012 11:24:50 +0200 Subject: #13993: HTMLParser is now able to handle broken end tags when strict=False. --- Lib/test/test_htmlparser.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'Lib/test/test_htmlparser.py') diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py index 7af9131108..2e7277e573 100644 --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -364,8 +364,9 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase): ('data', '<'), + ('comment', '/img'), + ('endtag', 'html<')]) def test_with_unquoted_attributes(self): # see #12008 @@ -403,6 +404,44 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase): ('starttag', 'form', [('action', 'bogus|&#()value')])]) + def test_invalid_end_tags(self): + # A collection of broken end tags.
is used as separator. + # see http://www.w3.org/TR/html5/tokenization.html#end-tag-open-state + # and #13993 + html = ('



' + '


') + expected = [('starttag', 'br', []), + # < is part of the name, / is discarded, p is an attribute + ('endtag', 'label<'), + ('starttag', 'br', []), + # text and attributes are discarded + ('endtag', 'div'), + ('starttag', 'br', []), + # comment because the first char after is ignored + ('starttag', 'br', [])] + self._run_check(html, expected) + + def test_broken_invalid_end_tag(self): + # This is technically wrong (the "> shouldn't be included in the 'data') + # but is probably not worth fixing it (in addition to all the cases of + # the previous test, it would require a full attribute parsing). + # see #13993 + html = 'This confuses the parser' + expected = [('starttag', 'b', []), + ('data', 'This'), + ('endtag', 'b'), + ('data', '"> confuses the parser')] + self._run_check(html, expected) + def test_correct_detection_of_start_tags(self): # see #13273 html = ('
The rain ' -- cgit v1.2.1