From 6b7003a18c2fa7378eb5ec5766ded01dee212c85 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Mon, 19 Dec 2011 07:28:08 +0200 Subject: [PATCH] #13576: add tests about the handling of (possibly broken) condcoms. --- Lib/markupbase.py | 4 ++++ Lib/test/test_htmlparser.py | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Lib/markupbase.py b/Lib/markupbase.py index 24808d185b..ddeb9835b8 100644 --- a/Lib/markupbase.py +++ b/Lib/markupbase.py @@ -108,6 +108,10 @@ class ParserBase: if decltype == "doctype": self.handle_decl(data) else: + # According to the HTML5 specs sections "8.2.4.44 Bogus + # comment state" and "8.2.4.45 Markup declaration open + # state", a comment token should be emitted. + # Calling unknown_decl provides more flexibility though. self.unknown_decl(data) return j + 1 if c in "\"'": diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py index 5dfe466225..14ed80c5d0 100644 --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -449,6 +449,48 @@ class AttributesTestCase(TestCaseBase): [("href", "http://www.example.org/\">;")]), ("data", "spam"), ("endtag", "a")]) + def test_condcoms(self): + html = ('' + '' + '') + expected = [('comment', "[if IE & !(lte IE 8)]>aren'tcondcomspretty?' + html = ('broken condcom' + '' + '' + 'foo' + '') + # According to the HTML5 specs sections "8.2.4.44 Bogus comment state" + # and "8.2.4.45 Markup declaration open state", comment tokens should + # be emitted instead of 'unknown decl', but calling unknown_decl + # provides more flexibility. + # See also Lib/_markupbase.py:parse_declaration + expected = [ + ('unknown decl', 'if !(IE)'), + ('data', 'broken condcom'), + ('unknown decl', 'endif'), + ('unknown decl', 'if ! IE'), + ('startendtag', 'link', [('href', 'favicon.tiff')]), + ('unknown decl', 'endif'), + ('unknown decl', 'if !IE 6'), + ('startendtag', 'img', [('src', 'firefox.png')]), + ('unknown decl', 'endif'), + ('unknown decl', 'if !ie 6'), + ('starttag', 'b', []), + ('data', 'foo'), + ('endtag', 'b'), + ('unknown decl', 'endif'), + ('unknown decl', 'if (!IE)|(lt IE 9)'), + ('startendtag', 'img', [('src', 'mammoth.bmp')]), + ('unknown decl', 'endif') + ] + self._run_check(html, expected) + def test_main(): test_support.run_unittest(HTMLParserTestCase, AttributesTestCase) -- 2.50.1