mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
#13993: HTMLParser is now able to handle broken end tags when strict=False.
This commit is contained in:
parent
efc66f9e36
commit
5211ffe4df
3 changed files with 71 additions and 17 deletions
|
@ -364,8 +364,9 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
|
|||
('data', '<<bc'),
|
||||
('endtag', 'a'),
|
||||
('endtag', 'html'),
|
||||
('data', '\n<img src="URL><//img></html'),
|
||||
('endtag', 'html')])
|
||||
('data', '\n<img src="URL>'),
|
||||
('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. <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_correct_detection_of_start_tags(self):
|
||||
# see #13273
|
||||
html = ('<div style="" ><b>The <a href="some_url">rain</a> '
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue