Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_htmlparser.py @ 74859:242b697449d8 3.2
#13960: HTMLParser is now able to handle broken comments when strict=False.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 10 Feb 2012 10:45:44 +0200 |
| parents | 4ddbb756b602 |
| children | df5e5eea7833 |
line wrap: on
line diff
--- a/Lib/test/test_htmlparser.py Thu Feb 09 18:26:59 2012 +0800 +++ b/Lib/test/test_htmlparser.py Fri Feb 10 10:45:44 2012 +0200 @@ -323,6 +323,23 @@ ("endtag", element_lower)], collector=Collector()) + def test_comments(self): + html = ("<!-- I'm a valid comment -->" + '<!--me too!-->' + '<!------>' + '<!---->' + '<!----I have many hyphens---->' + '<!-- I have a > in the middle -->' + '<!-- and I have -- in the middle! -->') + expected = [('comment', " I'm a valid comment "), + ('comment', 'me too!'), + ('comment', '--'), + ('comment', ''), + ('comment', '--I have many hyphens--'), + ('comment', ' I have a > in the middle '), + ('comment', ' and I have -- in the middle! ')] + self._run_check(html, expected) + def test_condcoms(self): html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->' '<!--[if IE 8]>condcoms<![endif]-->' @@ -426,6 +443,19 @@ # see #12888 self.assertEqual(p.unescape('{ ' * 1050), '{ ' * 1050) + def test_broken_comments(self): + html = ('<! not really a comment >' + '<! not a comment either -->' + '<! -- close enough -->' + '<!!! another bogus comment !!!>') + expected = [ + ('comment', ' not really a comment '), + ('comment', ' not a comment either --'), + ('comment', ' -- close enough --'), + ('comment', '!! another bogus comment !!!'), + ] + self._run_check(html, expected) + def test_broken_condcoms(self): # these condcoms are missing the '--' after '<!' and before the '>' html = ('<![if !(IE)]>broken condcom<![endif]>'
