diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-13 16:28:54 +0200 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2012-02-13 16:28:54 +0200 |
commit | f117443cb8afa3b2d91b4fef861db17866d6b6df (patch) | |
tree | 4355ba11b5406084325b960dbd4dc464ad8fa202 /Lib/test/test_htmlparser.py | |
parent | 4b92cc3f7924e455b7e41cf1a66034a44ede0cc0 (diff) | |
download | cpython-git-f117443cb8afa3b2d91b4fef861db17866d6b6df.tar.gz |
#13993: HTMLParser is now able to handle broken end tags.
Diffstat (limited to 'Lib/test/test_htmlparser.py')
-rw-r--r-- | Lib/test/test_htmlparser.py | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py index 29a721cf45..c15bb660e2 100644 --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -202,12 +202,12 @@ text self._run_check(["<!--abc-->", ""], output) def test_starttag_junk_chars(self): - self._parse_error("</>") - self._parse_error("</$>") + self._run_check("</>", []) + self._run_check("</$>", [('comment', '$')]) self._parse_error("</") self._parse_error("</a") self._parse_error("<a<a>") - self._parse_error("</a<a>") + self._run_check("</a<a>", [('endtag', 'a<a')]) self._parse_error("<!") self._parse_error("<a") self._parse_error("<a foo='bar'") @@ -232,6 +232,44 @@ text ("endtag", "p"), ]) + def test_invalid_end_tags(self): + # A collection of broken end tags. <br> is used as separator. + # see http://www.w3.org/TR/html5/tokenization.html#end-tag-open-state + # and #13993 + html = ('<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br>' + '</li class="unit"><br></li\r\n\t\t\t\t\t\t</ul><br></><br>') + 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 not a-zA-Z + ('comment', '<h4'), + ('starttag', 'br', []), + # attributes are discarded + ('endtag', 'li'), + ('starttag', 'br', []), + # everything till ul (included) is discarded + ('endtag', 'li'), + ('starttag', 'br', []), + # </> 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 = '<b>This</b attr=">"> confuses the parser' + expected = [('starttag', 'b', []), + ('data', 'This'), + ('endtag', 'b'), + ('data', '"> confuses the parser')] + self._run_check(html, expected) + def test_get_starttag_text(self): s = """<foo:bar \n one="1"\ttwo=2 >""" self._run_check_extra(s, [ |