annotate Lib/test/test_htmlparser.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 36c901fcfcda
children 695f988824bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 """Tests for HTMLParser.py."""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
47191
0912511b9897 Remove html package and fix test_htmlparser.
Georg Brandl <georg@python.org>
parents: 47169
diff changeset
3 import HTMLParser
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
4 import pprint
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 import unittest
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 21157
diff changeset
6 from test import test_support
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
47191
0912511b9897 Remove html package and fix test_htmlparser.
Georg Brandl <georg@python.org>
parents: 47169
diff changeset
9 class EventCollector(HTMLParser.HTMLParser):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 def __init__(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 self.events = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 self.append = self.events.append
47191
0912511b9897 Remove html package and fix test_htmlparser.
Georg Brandl <georg@python.org>
parents: 47169
diff changeset
14 HTMLParser.HTMLParser.__init__(self)
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 def get_events(self):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 # Normalize the list of events so that buffer artefacts don't
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 # separate runs of contiguous characters.
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 L = []
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 prevtype = None
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 for event in self.events:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 type = event[0]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 if type == prevtype == "data":
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 L[-1] = ("data", L[-1][1] + event[1])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 else:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 L.append(event)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 prevtype = type
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 self.events = L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 return L
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 # structure markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 def handle_starttag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 self.append(("starttag", tag, attrs))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 def handle_startendtag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 self.append(("startendtag", tag, attrs))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 def handle_endtag(self, tag):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 self.append(("endtag", tag))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 # all other markup
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 def handle_comment(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 self.append(("comment", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
47 def handle_charref(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
48 self.append(("charref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50 def handle_data(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51 self.append(("data", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
52
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
53 def handle_decl(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
54 self.append(("decl", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
55
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
56 def handle_entityref(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
57 self.append(("entityref", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
58
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
59 def handle_pi(self, data):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
60 self.append(("pi", data))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
61
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
62 def unknown_decl(self, decl):
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
63 self.append(("unknown decl", decl))
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
64
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
65
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
66 class EventCollectorExtra(EventCollector):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
67
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 def handle_starttag(self, tag, attrs):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69 EventCollector.handle_starttag(self, tag, attrs)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70 self.append(("starttag_text", self.get_starttag_text()))
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
71
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
72
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73 class TestCaseBase(unittest.TestCase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
75 def _run_check(self, source, expected_events, collector=EventCollector):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 parser = collector()
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77 for s in source:
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 parser.feed(s)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
79 parser.close()
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
80 events = parser.get_events()
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
81 if events != expected_events:
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
82 self.fail("received events did not match expected events\n"
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
83 "Expected:\n" + pprint.pformat(expected_events) +
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
84 "\nReceived:\n" + pprint.pformat(events))
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86 def _run_check_extra(self, source, events):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 self._run_check(source, events, EventCollectorExtra)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
88
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89 def _parse_error(self, source):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90 def parse(source=source):
47191
0912511b9897 Remove html package and fix test_htmlparser.
Georg Brandl <georg@python.org>
parents: 47169
diff changeset
91 parser = HTMLParser.HTMLParser()
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
92 parser.feed(source)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
93 parser.close()
47191
0912511b9897 Remove html package and fix test_htmlparser.
Georg Brandl <georg@python.org>
parents: 47169
diff changeset
94 self.assertRaises(HTMLParser.HTMLParseError, parse)
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
95
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
97 class HTMLParserTestCase(TestCaseBase):
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
98
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
99 def test_processing_instruction_only(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100 self._run_check("<?processing instruction>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
101 ("pi", "processing instruction"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102 ])
28660
5f1ef1882b25 Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents: 28297
diff changeset
103 self._run_check("<?processing instruction ?>", [
5f1ef1882b25 Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents: 28297
diff changeset
104 ("pi", "processing instruction ?"),
5f1ef1882b25 Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents: 28297
diff changeset
105 ])
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
107 def test_simple_html(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108 self._run_check("""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 <!DOCTYPE html PUBLIC 'foo'>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110 <HTML>&entity;&#32;
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
111 <!--comment1a
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
112 -></foo><bar>&lt;<?pi?></foo<bar
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
113 comment1b-->
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
114 <Img sRc='Bar' isMAP>sample
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
115 text
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
116 &#x201C;
74908
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
117 <!--comment2a-- --comment2b-->
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
118 </Html>
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
119 """, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
120 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
121 ("decl", "DOCTYPE html PUBLIC 'foo'"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
122 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
123 ("starttag", "html", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
124 ("entityref", "entity"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
125 ("charref", "32"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
126 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
127 ("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
128 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
129 ("starttag", "img", [("src", "Bar"), ("ismap", None)]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
130 ("data", "sample\ntext\n"),
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
131 ("charref", "x201C"),
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
132 ("data", "\n"),
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
133 ("comment", "comment2a-- --comment2b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
134 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 ("endtag", "html"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 ("data", "\n"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
137 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138
21157
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
139 def test_unclosed_entityref(self):
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
140 self._run_check("&entityref foo", [
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
141 ("entityref", "entityref"),
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
142 ("data", " foo"),
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
143 ])
e592472d55a3 Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents: 20069
diff changeset
144
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
145 def test_bad_nesting(self):
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
146 # Strangely, this *is* supposed to test that overlapping
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
147 # elements are allowed. HTMLParser is more geared toward
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
148 # lexing the input that parsing the structure.
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
149 self._run_check("<a><b></a></b>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
150 ("starttag", "a", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
151 ("starttag", "b", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
152 ("endtag", "a"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
153 ("endtag", "b"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
154 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
155
19410
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
156 def test_bare_ampersands(self):
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
157 self._run_check("this text & contains & ampersands &", [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
158 ("data", "this text & contains & ampersands &"),
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
159 ])
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
160
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
161 def test_bare_pointy_brackets(self):
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
162 self._run_check("this < text > contains < bare>pointy< brackets", [
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
163 ("data", "this < text > contains < bare>pointy< brackets"),
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
164 ])
c403af003884 Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents: 18985
diff changeset
165
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
166 def test_illegal_declarations(self):
74908
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
167 self._run_check('<!spacer type="block" height="25">',
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
168 [('comment', 'spacer type="block" height="25"')])
19683
8cbc74f5586b Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents: 19410
diff changeset
169
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
170 def test_starttag_end_boundary(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
171 self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
172 self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
173
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
174 def test_buffer_artefacts(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
175 output = [("starttag", "a", [("b", "<")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
176 self._run_check(["<a b='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
177 self._run_check(["<a ", "b='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
178 self._run_check(["<a b", "='<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
179 self._run_check(["<a b=", "'<'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
180 self._run_check(["<a b='<", "'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
181 self._run_check(["<a b='<'", ">"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
183 output = [("starttag", "a", [("b", ">")])]
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 self._run_check(["<a b='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
185 self._run_check(["<a ", "b='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186 self._run_check(["<a b", "='>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 self._run_check(["<a b=", "'>'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 self._run_check(["<a b='>", "'>"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 self._run_check(["<a b='>'", ">"], output)
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190
33432
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
191 output = [("comment", "abc")]
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
192 self._run_check(["", "<!--abc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
193 self._run_check(["<", "!--abc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
194 self._run_check(["<!", "--abc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
195 self._run_check(["<!-", "-abc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
196 self._run_check(["<!--", "abc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
197 self._run_check(["<!--a", "bc-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
198 self._run_check(["<!--ab", "c-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
199 self._run_check(["<!--abc", "-->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
200 self._run_check(["<!--abc-", "->"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
201 self._run_check(["<!--abc--", ">"], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
202 self._run_check(["<!--abc-->", ""], output)
4b708fa0a60a add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents: 32538
diff changeset
203
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
204 def test_starttag_junk_chars(self):
74909
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
205 self._run_check("</>", [])
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
206 self._run_check("</$>", [('comment', '$')])
74945
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
207 self._run_check("</", [('data', '</')])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
208 self._run_check("</a", [('data', '</a')])
74946
3d7904e3f4b9 #13987: HTMLParser is now able to handle malformed start tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74945
diff changeset
209 # XXX this might be wrong
3d7904e3f4b9 #13987: HTMLParser is now able to handle malformed start tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74945
diff changeset
210 self._run_check("<a<a>", [('data', '<a'), ('starttag', 'a', [])])
74909
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
211 self._run_check("</a<a>", [('endtag', 'a<a')])
74945
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
212 self._run_check("<!", [('data', '<!')])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
213 self._run_check("<a", [('data', '<a')])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
214 self._run_check("<a foo='bar'", [('data', "<a foo='bar'")])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
215 self._run_check("<a foo='bar", [('data', "<a foo='bar")])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
216 self._run_check("<a foo='>'", [('data', "<a foo='>'")])
11a31eb5da93 #13987: HTMLParser is now able to handle EOFs in the middle of a construct.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74915
diff changeset
217 self._run_check("<a foo='>", [('data', "<a foo='>")])
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
218
74915
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
219 def test_valid_doctypes(self):
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
220 # from http://www.w3.org/QA/2002/04/valid-dtd-list.html
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
221 dtds = ['HTML', # HTML5 doctype
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
222 ('HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
223 '"http://www.w3.org/TR/html4/strict.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
224 ('HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
225 '"http://www.w3.org/TR/html4/loose.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
226 ('html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
227 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
228 ('html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
229 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
230 ('math PUBLIC "-//W3C//DTD MathML 2.0//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
231 '"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
232 ('html PUBLIC "-//W3C//DTD '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
233 'XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
234 '"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
235 ('svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
236 '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"'),
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
237 'html PUBLIC "-//IETF//DTD HTML 2.0//EN"',
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
238 'html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"']
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
239 for dtd in dtds:
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
240 self._run_check("<!DOCTYPE %s>" % dtd,
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
241 [('decl', 'DOCTYPE ' + dtd)])
4743a3a1e669 Fix an index, add more tests, avoid raising errors for unknown declarations, and clean up comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74909
diff changeset
242
75116
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
243 def test_slashes_in_starttag(self):
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
244 self._run_check('<a foo="var"/>', [('startendtag', 'a', [('foo', 'var')])])
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
245 html = ('<img width=902 height=250px '
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
246 'src="/sites/default/files/images/homepage/foo.jpg" '
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
247 '/*what am I doing here*/ />')
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
248 expected = [(
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
249 'startendtag', 'img',
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
250 [('width', '902'), ('height', '250px'),
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
251 ('src', '/sites/default/files/images/homepage/foo.jpg'),
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
252 ('*what', None), ('am', None), ('i', None),
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
253 ('doing', None), ('here*', None)]
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
254 )]
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
255 self._run_check(html, expected)
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
256 html = ('<a / /foo/ / /=/ / /bar/ / />'
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
257 '<a / /foo/ / /=/ / /bar/ / >')
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
258 expected = [
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
259 ('startendtag', 'a', [('foo', None), ('=', None), ('bar', None)]),
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
260 ('starttag', 'a', [('foo', None), ('=', None), ('bar', None)])
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
261 ]
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
262 self._run_check(html, expected)
76413
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
263 #see issue #14538
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
264 html = ('<meta><meta / ><meta // ><meta / / >'
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
265 '<meta/><meta /><meta //><meta//>')
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
266 expected = [
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
267 ('starttag', 'meta', []), ('starttag', 'meta', []),
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
268 ('starttag', 'meta', []), ('starttag', 'meta', []),
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
269 ('startendtag', 'meta', []), ('startendtag', 'meta', []),
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
270 ('startendtag', 'meta', []), ('startendtag', 'meta', []),
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
271 ]
36c901fcfcda #14538: HTMLParser can now parse correctly start tags that contain a bare /.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 75116
diff changeset
272 self._run_check(html, expected)
75116
37c824c3efe8 HTMLParser is now able to handle slashes in the start tag.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74946
diff changeset
273
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
274 def test_declaration_junk_chars(self):
74908
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
275 self._run_check("<!DOCTYPE foo $ >", [('decl', 'DOCTYPE foo $ ')])
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
276
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
277 def test_startendtag(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
278 self._run_check("<p/>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
279 ("startendtag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
280 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
281 self._run_check("<p></p>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
282 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
283 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
284 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
285 self._run_check("<p><img src='foo' /></p>", [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
286 ("starttag", "p", []),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
287 ("startendtag", "img", [("src", "foo")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288 ("endtag", "p"),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
289 ])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
290
74909
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
291 def test_invalid_end_tags(self):
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
292 # A collection of broken end tags. <br> is used as separator.
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
293 # see http://www.w3.org/TR/html5/tokenization.html#end-tag-open-state
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
294 # and #13993
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
295 html = ('<br></label</p><br></div end tmAd-leaderBoard><br></<h4><br>'
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
296 '</li class="unit"><br></li\r\n\t\t\t\t\t\t</ul><br></><br>')
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
297 expected = [('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
298 # < is part of the name, / is discarded, p is an attribute
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
299 ('endtag', 'label<'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
300 ('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
301 # text and attributes are discarded
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
302 ('endtag', 'div'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
303 ('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
304 # comment because the first char after </ is not a-zA-Z
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
305 ('comment', '<h4'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
306 ('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
307 # attributes are discarded
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
308 ('endtag', 'li'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
309 ('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
310 # everything till ul (included) is discarded
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
311 ('endtag', 'li'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
312 ('starttag', 'br', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
313 # </> is ignored
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
314 ('starttag', 'br', [])]
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
315 self._run_check(html, expected)
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
316
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
317 def test_broken_invalid_end_tag(self):
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
318 # This is technically wrong (the "> shouldn't be included in the 'data')
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
319 # but is probably not worth fixing it (in addition to all the cases of
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
320 # the previous test, it would require a full attribute parsing).
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
321 # see #13993
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
322 html = '<b>This</b attr=">"> confuses the parser'
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
323 expected = [('starttag', 'b', []),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
324 ('data', 'This'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
325 ('endtag', 'b'),
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
326 ('data', '"> confuses the parser')]
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
327 self._run_check(html, expected)
a349448474ea #13993: HTMLParser is now able to handle broken end tags.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74908
diff changeset
328
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
329 def test_get_starttag_text(self):
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
330 s = """<foo:bar \n one="1"\ttwo=2 >"""
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
331 self._run_check_extra(s, [
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
332 ("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
333 ("starttag_text", s)])
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
334
18985
ba9e4f55133f Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents: 18634
diff changeset
335 def test_cdata_content(self):
73273
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
336 contents = [
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
337 '<!-- not a comment --> &not-an-entity-ref;',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
338 "<not a='start tag'>",
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
339 '<a href="" /> <p> <span></span>',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
340 'foo = "</scr" + "ipt>";',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
341 'foo = "</SCRIPT" + ">";',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
342 'foo = <\n/script> ',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
343 '<!-- document.write("</scr" + "ipt>"); -->',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
344 ('\n//<![CDATA[\n'
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
345 'document.write(\'<s\'+\'cript type="text/javascript" '
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
346 'src="http://www.example.org/r=\'+new '
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
347 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'),
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
348 '\n<!-- //\nvar foo = 3.14;\n// -->\n',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
349 'foo = "</sty" + "le>";',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
350 u'<!-- \u2603 -->',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
351 # these two should be invalid according to the HTML 5 spec,
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
352 # section 8.1.2.2
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
353 #'foo = </\nscript>',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
354 #'foo = </ script>',
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
355 ]
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
356 elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style']
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
357 for content in contents:
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
358 for element in elements:
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
359 element_lower = element.lower()
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
360 s = u'<{element}>{content}</{element}>'.format(element=element,
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
361 content=content)
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
362 self._run_check(s, [("starttag", element_lower, []),
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
363 ("data", content),
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
364 ("endtag", element_lower)])
0a5eb57d5876 #670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 69160
diff changeset
365
73608
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
366 def test_cdata_with_closing_tags(self):
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
367 # see issue #13358
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
368 # make sure that HTMLParser calls handle_data only once for each CDATA.
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
369 # The normal event collector normalizes the events in get_events,
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
370 # so we override it to return the original list of events.
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
371 class Collector(EventCollector):
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
372 def get_events(self):
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
373 return self.events
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
374
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
375 content = """<!-- not a comment --> &not-an-entity-ref;
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
376 <a href="" /> </p><p> &amp; <span></span></style>
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
377 '</script' + '>' </html> </head> </scripter>!"""
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
378 for element in [' script', 'script ', ' script ',
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
379 '\nscript', 'script\n', '\nscript\n']:
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
380 s = u'<script>{content}</{element}>'.format(element=element,
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
381 content=content)
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
382 self._run_check(s, [("starttag", "script", []),
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
383 ("data", content),
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
384 ("endtag", "script")],
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
385 collector=Collector)
91163aa3d5b4 #13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73545
diff changeset
386
61885
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
387 def test_malformatted_charref(self):
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
388 self._run_check("<p>&#bad;</p>", [
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
389 ("starttag", "p", []),
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
390 ("data", "&#bad;"),
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
391 ("endtag", "p"),
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
392 ])
ebda6803f8d5 Issue #6662: Fix parsing of malformatted charref (&#bad;)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 47191
diff changeset
393
67188
05cccd4257a2 Fix Issue10759 - HTMLParser.unescape() to handle malform charrefs.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61885
diff changeset
394 def test_unescape_function(self):
05cccd4257a2 Fix Issue10759 - HTMLParser.unescape() to handle malform charrefs.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61885
diff changeset
395 parser = HTMLParser.HTMLParser()
05cccd4257a2 Fix Issue10759 - HTMLParser.unescape() to handle malform charrefs.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61885
diff changeset
396 self.assertEqual(parser.unescape('&#bad;'),'&#bad;')
05cccd4257a2 Fix Issue10759 - HTMLParser.unescape() to handle malform charrefs.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61885
diff changeset
397 self.assertEqual(parser.unescape('&#0038;'),'&')
05cccd4257a2 Fix Issue10759 - HTMLParser.unescape() to handle malform charrefs.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61885
diff changeset
398
17854
028a1d39efb6 Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff changeset
399
73544
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
400
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
401 class AttributesTestCase(TestCaseBase):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
402
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
403 def test_attr_syntax(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
404 output = [
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
405 ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
406 ]
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
407 self._run_check("""<a b='v' c="v" d=v e>""", output)
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
408 self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
409 self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
410 self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
411
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
412 def test_attr_values(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
413 self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
414 [("starttag", "a", [("b", "xxx\n\txxx"),
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
415 ("c", "yyy\t\nyyy"),
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
416 ("d", "\txyz\n")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
417 self._run_check("""<a b='' c="">""",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
418 [("starttag", "a", [("b", ""), ("c", "")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
419 # Regression test for SF patch #669683.
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
420 self._run_check("<e a=rgb(1,2,3)>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
421 [("starttag", "e", [("a", "rgb(1,2,3)")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
422 # Regression test for SF bug #921657.
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
423 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
424 "<a href=mailto:xyz@example.com>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
425 [("starttag", "a", [("href", "mailto:xyz@example.com")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
426
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
427 def test_attr_nonascii(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
428 # see issue 7311
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
429 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
430 u"<img src=/foo/bar.png alt=\u4e2d\u6587>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
431 [("starttag", "img", [("src", "/foo/bar.png"),
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
432 ("alt", u"\u4e2d\u6587")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
433 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
434 u"<a title='\u30c6\u30b9\u30c8' href='\u30c6\u30b9\u30c8.html'>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
435 [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
436 ("href", u"\u30c6\u30b9\u30c8.html")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
437 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
438 u'<a title="\u30c6\u30b9\u30c8" href="\u30c6\u30b9\u30c8.html">',
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
439 [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
440 ("href", u"\u30c6\u30b9\u30c8.html")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
441
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
442 def test_attr_entity_replacement(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
443 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
444 "<a b='&amp;&gt;&lt;&quot;&apos;'>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
445 [("starttag", "a", [("b", "&><\"'")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
446
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
447 def test_attr_funky_names(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
448 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
449 "<a a.b='v' c:d=v e-f=v>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
450 [("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")])])
73545
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
451 self._run_check(
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
452 "<a $><b $=%><c \=/>",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
453 [("starttag", "a", [("$", None)]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
454 ("starttag", "b", [("$", "%")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
455 ("starttag", "c", [("\\", "/")])])
73544
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
456
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
457 def test_entityrefs_in_attributes(self):
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
458 self._run_check(
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
459 "<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>",
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
460 [("starttag", "html", [("foo", u"\u20AC&aa&unsupported;")])])
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
461
73545
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
462 def test_entities_in_attribute_value(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
463 # see #1200313
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
464 for entity in ['&', '&amp;', '&#38;', '&#x26;']:
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
465 self._run_check('<a href="%s">' % entity,
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
466 [("starttag", "a", [("href", "&")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
467 self._run_check("<a href='%s'>" % entity,
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
468 [("starttag", "a", [("href", "&")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
469 self._run_check("<a href=%s>" % entity,
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
470 [("starttag", "a", [("href", "&")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
471
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
472 def test_malformed_attributes(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
473 # see #13357
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
474 html = (
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
475 "<a href=test'style='color:red;bad1'>test - bad1</a>"
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
476 "<a href=test'+style='color:red;ba2'>test - bad2</a>"
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
477 "<a href=test'&nbsp;style='color:red;bad3'>test - bad3</a>"
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
478 "<a href = test'&nbsp;style='color:red;bad4' >test - bad4</a>"
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
479 )
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
480 expected = [
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
481 ('starttag', 'a', [('href', "test'style='color:red;bad1'")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
482 ('data', 'test - bad1'), ('endtag', 'a'),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
483 ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
484 ('data', 'test - bad2'), ('endtag', 'a'),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
485 ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad3'")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
486 ('data', 'test - bad3'), ('endtag', 'a'),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
487 ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad4'")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
488 ('data', 'test - bad4'), ('endtag', 'a')
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
489 ]
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
490 self._run_check(html, expected)
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
491
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
492 def test_malformed_adjacent_attributes(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
493 # see #12629
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
494 self._run_check('<x><y z=""o"" /></x>',
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
495 [('starttag', 'x', []),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
496 ('startendtag', 'y', [('z', ''), ('o""', None)]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
497 ('endtag', 'x')])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
498 self._run_check('<x><y z="""" /></x>',
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
499 [('starttag', 'x', []),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
500 ('startendtag', 'y', [('z', ''), ('""', None)]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
501 ('endtag', 'x')])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
502
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
503 # see #755670 for the following 3 tests
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
504 def test_adjacent_attributes(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
505 self._run_check('<a width="100%"cellspacing=0>',
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
506 [("starttag", "a",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
507 [("width", "100%"), ("cellspacing","0")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
508
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
509 self._run_check('<a id="foo"class="bar">',
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
510 [("starttag", "a",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
511 [("id", "foo"), ("class","bar")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
512
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
513 def test_missing_attribute_value(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
514 self._run_check('<a v=>',
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
515 [("starttag", "a", [("v", "")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
516
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
517 def test_javascript_attribute_value(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
518 self._run_check("<a href=javascript:popup('/popup/help.html')>",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
519 [("starttag", "a",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
520 [("href", "javascript:popup('/popup/help.html')")])])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
521
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
522 def test_end_tag_in_attribute_value(self):
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
523 # see #1745761
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
524 self._run_check("<a href='http://www.example.org/\">;'>spam</a>",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
525 [("starttag", "a",
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
526 [("href", "http://www.example.org/\">;")]),
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
527 ("data", "spam"), ("endtag", "a")])
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
528
74908
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
529 def test_comments(self):
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
530 html = ("<!-- I'm a valid comment -->"
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
531 '<!--me too!-->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
532 '<!------>'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
533 '<!---->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
534 '<!----I have many hyphens---->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
535 '<!-- I have a > in the middle -->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
536 '<!-- and I have -- in the middle! -->')
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
537 expected = [('comment', " I'm a valid comment "),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
538 ('comment', 'me too!'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
539 ('comment', '--'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
540 ('comment', ''),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
541 ('comment', '--I have many hyphens--'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
542 ('comment', ' I have a > in the middle '),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
543 ('comment', ' and I have -- in the middle! ')]
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
544 self._run_check(html, expected)
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
545
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
546 def test_broken_comments(self):
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
547 html = ('<! not really a comment >'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
548 '<! not a comment either -->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
549 '<! -- close enough -->'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
550 '<!><!<-- this was an empty comment>'
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
551 '<!!! another bogus comment !!!>')
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
552 expected = [
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
553 ('comment', ' not really a comment '),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
554 ('comment', ' not a comment either --'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
555 ('comment', ' -- close enough --'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
556 ('comment', ''),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
557 ('comment', '<-- this was an empty comment'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
558 ('comment', '!! another bogus comment !!!'),
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
559 ]
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
560 self._run_check(html, expected)
333e3acf2008 #13960: HTMLParser is now able to handle broken comments.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 74069
diff changeset
561
74069
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
562 def test_condcoms(self):
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
563 html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
564 '<!--[if IE 8]>condcoms<![endif]-->'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
565 '<!--[if lte IE 7]>pretty?<![endif]-->')
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
566 expected = [('comment', "[if IE & !(lte IE 8)]>aren't<![endif]"),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
567 ('comment', '[if IE 8]>condcoms<![endif]'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
568 ('comment', '[if lte IE 7]>pretty?<![endif]')]
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
569 self._run_check(html, expected)
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
570
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
571 def test_broken_condcoms(self):
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
572 # these condcoms are missing the '--' after '<!' and before the '>'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
573 html = ('<![if !(IE)]>broken condcom<![endif]>'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
574 '<![if ! IE]><link href="favicon.tiff"/><![endif]>'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
575 '<![if !IE 6]><img src="firefox.png" /><![endif]>'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
576 '<![if !ie 6]><b>foo</b><![endif]>'
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
577 '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>')
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
578 # According to the HTML5 specs sections "8.2.4.44 Bogus comment state"
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
579 # and "8.2.4.45 Markup declaration open state", comment tokens should
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
580 # be emitted instead of 'unknown decl', but calling unknown_decl
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
581 # provides more flexibility.
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
582 # See also Lib/_markupbase.py:parse_declaration
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
583 expected = [
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
584 ('unknown decl', 'if !(IE)'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
585 ('data', 'broken condcom'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
586 ('unknown decl', 'endif'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
587 ('unknown decl', 'if ! IE'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
588 ('startendtag', 'link', [('href', 'favicon.tiff')]),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
589 ('unknown decl', 'endif'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
590 ('unknown decl', 'if !IE 6'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
591 ('startendtag', 'img', [('src', 'firefox.png')]),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
592 ('unknown decl', 'endif'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
593 ('unknown decl', 'if !ie 6'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
594 ('starttag', 'b', []),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
595 ('data', 'foo'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
596 ('endtag', 'b'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
597 ('unknown decl', 'endif'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
598 ('unknown decl', 'if (!IE)|(lt IE 9)'),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
599 ('startendtag', 'img', [('src', 'mammoth.bmp')]),
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
600 ('unknown decl', 'endif')
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
601 ]
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
602 self._run_check(html, expected)
9c60fd12664f #13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73608
diff changeset
603
73545
3c3009f63700 #1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73544
diff changeset
604
20069
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
605 def test_main():
73544
da8212a27e3c Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73273
diff changeset
606 test_support.run_unittest(HTMLParserTestCase, AttributesTestCase)
20069
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
607
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
608
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
609 if __name__ == "__main__":
90a4f23abda7 Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents: 19687
diff changeset
610 test_main()