Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_htmlparser.py @ 74135:9c19df6c8ea0 3.2
News entry for Issue12798
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Fri, 23 Dec 2011 11:11:21 +0800 |
| parents | 4ddbb756b602 |
| children | 242b697449d8 |
| 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 |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
3 import html.parser |
|
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 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
45471
diff
changeset
|
6 from test import 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 |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
9 class EventCollector(html.parser.HTMLParser): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
11 def __init__(self, *args, **kw): |
|
17854
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 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
14 html.parser.HTMLParser.__init__(self, *args, **kw) |
|
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 |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
75 def get_collector(self): |
|
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
76 raise NotImplementedError |
|
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
77 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
78 def _run_check(self, source, expected_events, collector=None): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
79 if collector is None: |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
80 collector = self.get_collector() |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
81 parser = collector |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
82 for s in source: |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
83 parser.feed(s) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
84 parser.close() |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 "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
|
89 "\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
|
90 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 def _run_check_extra(self, source, events): |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
92 self._run_check(source, events, EventCollectorExtra()) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
93 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
94 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
|
95 def parse(source=source): |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
96 parser = html.parser.HTMLParser() |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
97 parser.feed(source) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
98 parser.close() |
|
47205
7aa9ad658014
Change test_htmlparser to reflect the HTMLParser -> html.parser
Mark Dickinson <dickinsm@gmail.com>
parents:
47201
diff
changeset
|
99 self.assertRaises(html.parser.HTMLParseError, parse) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
100 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
101 |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
102 class HTMLParserStrictTestCase(TestCaseBase): |
|
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
103 |
|
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
104 def get_collector(self): |
|
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
105 return EventCollector(strict=True) |
|
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_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
|
108 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
|
109 ("pi", "processing instruction"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
110 ]) |
|
28660
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
111 self._run_check("<?processing instruction ?>", [ |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
112 ("pi", "processing instruction ?"), |
|
5f1ef1882b25
Add test that demonstrates SGML-style handling of processing
Fred Drake <fdrake@acm.org>
parents:
28297
diff
changeset
|
113 ]) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
114 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
115 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
|
116 self._run_check(""" |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
117 <!DOCTYPE html PUBLIC 'foo'> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
118 <HTML>&entity;  |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
119 <!--comment1a |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
120 -></foo><bar><<?pi?></foo<bar |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
121 comment1b--> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
122 <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
|
123 text |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
124 “ |
|
36914
f1eaae7f962d
Bug #1442874: handle "<!>", the empty SGML comment
Georg Brandl <georg@python.org>
parents:
33432
diff
changeset
|
125 <!--comment2a-- --comment2b--><!> |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
126 </Html> |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
127 """, [ |
|
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 ("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
|
130 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
131 ("starttag", "html", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
132 ("entityref", "entity"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
133 ("charref", "32"), |
|
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 ("comment", "comment1a\n-></foo><bar><<?pi?></foo<bar\ncomment1b"), |
|
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 ("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
|
138 ("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
|
139 ("charref", "x201C"), |
|
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
140 ("data", "\n"), |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
141 ("comment", "comment2a-- --comment2b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
142 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
143 ("endtag", "html"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
144 ("data", "\n"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
145 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
146 |
|
61889
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
147 def test_malformatted_charref(self): |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
148 self._run_check("<p>&#bad;</p>", [ |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
149 ("starttag", "p", []), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
150 ("data", "&#bad;"), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
151 ("endtag", "p"), |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
152 ]) |
|
bf04eaf1af74
Recorded merge of revisions 81500-81501 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47205
diff
changeset
|
153 |
|
21157
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
154 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
|
155 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
|
156 ("entityref", "entityref"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
157 ("data", " foo"), |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
158 ]) |
|
e592472d55a3
Add a test that makes sure unclosed entity references are handled consitently.
Fred Drake <fdrake@acm.org>
parents:
20069
diff
changeset
|
159 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
160 def test_doctype_decl(self): |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
161 inside = """\ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
162 DOCTYPE html [ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
163 <!ELEMENT html - O EMPTY> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
164 <!ATTLIST html |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
165 version CDATA #IMPLIED |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
166 profile CDATA 'DublinCore'> |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
167 <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'> |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
168 <!ENTITY myEntity 'internal parsed entity'> |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
169 <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'> |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
170 <!ENTITY % paramEntity 'name|name|name'> |
|
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
171 %paramEntity; |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
172 <!-- comment --> |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
173 ]""" |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
174 self._run_check("<!%s>" % inside, [ |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
175 ("decl", inside), |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
176 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
177 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
178 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
|
179 # 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
|
180 # 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
|
181 # 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
|
182 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
|
183 ("starttag", "a", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
184 ("starttag", "b", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
185 ("endtag", "a"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
186 ("endtag", "b"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
187 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
188 |
|
19410
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
189 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
|
190 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
|
191 ("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
|
192 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
193 |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
194 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
|
195 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
|
196 ("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
|
197 ]) |
|
c403af003884
Deal more appropriately with bare ampersands and pointy brackets; this
Fred Drake <fdrake@acm.org>
parents:
18985
diff
changeset
|
198 |
|
19683
8cbc74f5586b
Enhanced the test for DOCTYPE declarations, added a test for dealing with
Fred Drake <fdrake@acm.org>
parents:
19410
diff
changeset
|
199 def test_illegal_declarations(self): |
|
19687
3731ad1d9033
HTMLParser is allowed to be more strict than sgmllib, so let's not
Fred Drake <fdrake@acm.org>
parents:
19683
diff
changeset
|
200 self._parse_error('<!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
|
201 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
206 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
|
207 output = [("starttag", "a", [("b", "<")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
215 output = [("starttag", "a", [("b", ">")])] |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 |
|
33432
4b708fa0a60a
add tests that make sure buffer boundaries are handled properly for SGML comments
Fred Drake <fdrake@acm.org>
parents:
32538
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
236 def test_starttag_junk_chars(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
237 self._parse_error("</>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
238 self._parse_error("</$>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
239 self._parse_error("</") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
240 self._parse_error("</a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
241 self._parse_error("<a<a>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
242 self._parse_error("</a<a>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
243 self._parse_error("<!") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
244 self._parse_error("<a") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
245 self._parse_error("<a foo='bar'") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
246 self._parse_error("<a foo='bar") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
247 self._parse_error("<a foo='>'") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
248 self._parse_error("<a foo='>") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
249 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
250 def test_declaration_junk_chars(self): |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
251 self._parse_error("<!DOCTYPE foo $ >") |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
252 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
253 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
|
254 self._run_check("<p/>", [ |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
255 ("startendtag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
256 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
257 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
|
258 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
259 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
260 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
261 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
|
262 ("starttag", "p", []), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
263 ("startendtag", "img", [("src", "foo")]), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
264 ("endtag", "p"), |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
265 ]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
266 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 ("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
|
271 ("starttag_text", s)]) |
|
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
272 |
|
18985
ba9e4f55133f
Fix stupid bug: when migrating these tests from the Zope repository, the
Fred Drake <fdrake@acm.org>
parents:
18634
diff
changeset
|
273 def test_cdata_content(self): |
|
73274
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
274 contents = [ |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
275 '<!-- not a comment --> ¬-an-entity-ref;', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
276 "<not a='start tag'>", |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
277 '<a href="" /> <p> <span></span>', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
278 'foo = "</scr" + "ipt>";', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
279 'foo = "</SCRIPT" + ">";', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
280 'foo = <\n/script> ', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
281 '<!-- document.write("</scr" + "ipt>"); -->', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
282 ('\n//<![CDATA[\n' |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
283 'document.write(\'<s\'+\'cript type="text/javascript" ' |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
284 'src="http://www.example.org/r=\'+new ' |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
285 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'), |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
286 '\n<!-- //\nvar foo = 3.14;\n// -->\n', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
287 'foo = "</sty" + "le>";', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
288 '<!-- \u2603 -->', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
289 # these two should be invalid according to the HTML 5 spec, |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
290 # section 8.1.2.2 |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
291 #'foo = </\nscript>', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
292 #'foo = </ script>', |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
293 ] |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
294 elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style'] |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
295 for content in contents: |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
296 for element in elements: |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
297 element_lower = element.lower() |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
298 s = '<{element}>{content}</{element}>'.format(element=element, |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
299 content=content) |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
300 self._run_check(s, [("starttag", element_lower, []), |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
301 ("data", content), |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
302 ("endtag", element_lower)]) |
|
a6f2244b251f
#670664: Fix HTMLParser to correctly handle the content of ``<script>...</script>`` and ``<style>...</style>``.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73159
diff
changeset
|
303 |
|
73609
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
304 def test_cdata_with_closing_tags(self): |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
305 # see issue #13358 |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
306 # make sure that HTMLParser calls handle_data only once for each CDATA. |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
307 # The normal event collector normalizes the events in get_events, |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
308 # so we override it to return the original list of events. |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
309 class Collector(EventCollector): |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
310 def get_events(self): |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
311 return self.events |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
312 |
|
73609
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
313 content = """<!-- not a comment --> ¬-an-entity-ref; |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
314 <a href="" /> </p><p> <span></span></style> |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
315 '</script' + '>'""" |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
316 for element in [' script', 'script ', ' script ', |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
317 '\nscript', 'script\n', '\nscript\n']: |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
318 element_lower = element.lower().strip() |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
319 s = '<script>{content}</{element}>'.format(element=element, |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
320 content=content) |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
321 self._run_check(s, [("starttag", element_lower, []), |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
322 ("data", content), |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
323 ("endtag", element_lower)], |
|
0a32e7e3aa1f
#13358: HTMLParser now calls handle_data only once for each CDATA.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73547
diff
changeset
|
324 collector=Collector()) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
325 |
|
74070
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
326 def test_condcoms(self): |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
327 html = ('<!--[if IE & !(lte IE 8)]>aren\'t<![endif]-->' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
328 '<!--[if IE 8]>condcoms<![endif]-->' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
329 '<!--[if lte IE 7]>pretty?<![endif]-->') |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
330 expected = [('comment', "[if IE & !(lte IE 8)]>aren't<![endif]"), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
331 ('comment', '[if IE 8]>condcoms<![endif]'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
332 ('comment', '[if lte IE 7]>pretty?<![endif]')] |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
333 self._run_check(html, expected) |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
334 |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
335 |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
336 class HTMLParserTolerantTestCase(HTMLParserStrictTestCase): |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
337 |
|
73279
4404e784918c
Avoid reusing the same collector in the tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73277
diff
changeset
|
338 def get_collector(self): |
|
4404e784918c
Avoid reusing the same collector in the tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73277
diff
changeset
|
339 return EventCollector(strict=False) |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
340 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
341 def test_tolerant_parsing(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
342 self._run_check('<html <html>te>>xt&a<<bc</a></html>\n' |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
343 '<img src="URL><//img></html</html>', [ |
|
73547
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
344 ('starttag', 'html', [('<html', None)]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
345 ('data', 'te>>xt'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
346 ('entityref', 'a'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
347 ('data', '<<bc'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
348 ('endtag', 'a'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
349 ('endtag', 'html'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
350 ('data', '\n<img src="URL><//img></html'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
351 ('endtag', 'html')]) |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
352 |
|
73277
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
353 def test_with_unquoted_attributes(self): |
|
73279
4404e784918c
Avoid reusing the same collector in the tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73277
diff
changeset
|
354 # see #12008 |
|
73277
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
355 html = ("<html><body bgcolor=d0ca90 text='181008'>" |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
356 "<table cellspacing=0 cellpadding=1 width=100% ><tr>" |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
357 "<td align=left><font size=-1>" |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
358 "- <a href=/rabota/><span class=en> software-and-i</span></a>" |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
359 "- <a href='/1/'><span class=en> library</span></a></table>") |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
360 expected = [ |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
361 ('starttag', 'html', []), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
362 ('starttag', 'body', [('bgcolor', 'd0ca90'), ('text', '181008')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
363 ('starttag', 'table', |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
364 [('cellspacing', '0'), ('cellpadding', '1'), ('width', '100%')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
365 ('starttag', 'tr', []), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
366 ('starttag', 'td', [('align', 'left')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
367 ('starttag', 'font', [('size', '-1')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
368 ('data', '- '), ('starttag', 'a', [('href', '/rabota/')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
369 ('starttag', 'span', [('class', 'en')]), ('data', ' software-and-i'), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
370 ('endtag', 'span'), ('endtag', 'a'), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
371 ('data', '- '), ('starttag', 'a', [('href', '/1/')]), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
372 ('starttag', 'span', [('class', 'en')]), ('data', ' library'), |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
373 ('endtag', 'span'), ('endtag', 'a'), ('endtag', 'table') |
|
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
374 ] |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
375 self._run_check(html, expected) |
|
73277
6107a84e3c44
#12008: add a test.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73274
diff
changeset
|
376 |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
377 def test_comma_between_attributes(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
378 self._run_check('<form action="/xxx.php?a=1&b=2&", ' |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
379 'method="post">', [ |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
380 ('starttag', 'form', |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
381 [('action', '/xxx.php?a=1&b=2&'), |
|
73547
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
382 (',', None), ('method', 'post')])]) |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
383 |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
384 def test_weird_chars_in_unquoted_attribute_values(self): |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
385 self._run_check('<form action=bogus|&#()value>', [ |
|
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
386 ('starttag', 'form', |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
387 [('action', 'bogus|&#()value')])]) |
|
66623
1cbfeffea19f
#1486713: Add a tolerant mode to HTMLParser.
R. David Murray <rdmurray@bitdance.com>
parents:
61889
diff
changeset
|
388 |
|
73279
4404e784918c
Avoid reusing the same collector in the tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73277
diff
changeset
|
389 def test_correct_detection_of_start_tags(self): |
|
4404e784918c
Avoid reusing the same collector in the tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73277
diff
changeset
|
390 # see #13273 |
|
73159
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
391 html = ('<div style="" ><b>The <a href="some_url">rain</a> ' |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
392 '<br /> in <span>Spain</span></b></div>') |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
393 expected = [ |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
394 ('starttag', 'div', [('style', '')]), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
395 ('starttag', 'b', []), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
396 ('data', 'The '), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
397 ('starttag', 'a', [('href', 'some_url')]), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
398 ('data', 'rain'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
399 ('endtag', 'a'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
400 ('data', ' '), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
401 ('startendtag', 'br', []), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
402 ('data', ' in '), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
403 ('starttag', 'span', []), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
404 ('data', 'Spain'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
405 ('endtag', 'span'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
406 ('endtag', 'b'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
407 ('endtag', 'div') |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
408 ] |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
409 self._run_check(html, expected) |
|
73159
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
410 |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
411 html = '<div style="", foo = "bar" ><b>The <a href="some_url">rain</a>' |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
412 expected = [ |
|
73547
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
413 ('starttag', 'div', [('style', ''), (',', None), ('foo', 'bar')]), |
|
73159
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
414 ('starttag', 'b', []), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
415 ('data', 'The '), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
416 ('starttag', 'a', [('href', 'some_url')]), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
417 ('data', 'rain'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
418 ('endtag', 'a'), |
|
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
419 ] |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
420 self._run_check(html, expected) |
|
73159
41d41776aa6d
#13273: fix a bug that prevented HTMLParser to properly detect some tags when strict=False.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72270
diff
changeset
|
421 |
|
67189
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
422 def test_unescape_function(self): |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
423 p = html.parser.HTMLParser() |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
424 self.assertEqual(p.unescape('&#bad;'),'&#bad;') |
|
3546ce1aa355
Merged revisions 87542 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61889
diff
changeset
|
425 self.assertEqual(p.unescape('&'),'&') |
|
72270
9896fc2a8167
#12888: Fix a bug in HTMLParser.unescape that prevented it to escape more than 128 entities. Patch by Peter Otten.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69189
diff
changeset
|
426 # see #12888 |
|
9896fc2a8167
#12888: Fix a bug in HTMLParser.unescape that prevented it to escape more than 128 entities. Patch by Peter Otten.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69189
diff
changeset
|
427 self.assertEqual(p.unescape('{ ' * 1050), '{ ' * 1050) |
|
17854
028a1d39efb6
Added test suite for the new HTMLParser module, originally from the
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
428 |
|
74070
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
429 def test_broken_condcoms(self): |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
430 # these condcoms are missing the '--' after '<!' and before the '>' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
431 html = ('<![if !(IE)]>broken condcom<![endif]>' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
432 '<![if ! IE]><link href="favicon.tiff"/><![endif]>' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
433 '<![if !IE 6]><img src="firefox.png" /><![endif]>' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
434 '<![if !ie 6]><b>foo</b><![endif]>' |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
435 '<![if (!IE)|(lt IE 9)]><img src="mammoth.bmp" /><![endif]>') |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
436 # According to the HTML5 specs sections "8.2.4.44 Bogus comment state" |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
437 # and "8.2.4.45 Markup declaration open state", comment tokens should |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
438 # be emitted instead of 'unknown decl', but calling unknown_decl |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
439 # provides more flexibility. |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
440 # See also Lib/_markupbase.py:parse_declaration |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
441 expected = [ |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
442 ('unknown decl', 'if !(IE)'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
443 ('data', 'broken condcom'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
444 ('unknown decl', 'endif'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
445 ('unknown decl', 'if ! IE'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
446 ('startendtag', 'link', [('href', 'favicon.tiff')]), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
447 ('unknown decl', 'endif'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
448 ('unknown decl', 'if !IE 6'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
449 ('startendtag', 'img', [('src', 'firefox.png')]), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
450 ('unknown decl', 'endif'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
451 ('unknown decl', 'if !ie 6'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
452 ('starttag', 'b', []), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
453 ('data', 'foo'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
454 ('endtag', 'b'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
455 ('unknown decl', 'endif'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
456 ('unknown decl', 'if (!IE)|(lt IE 9)'), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
457 ('startendtag', 'img', [('src', 'mammoth.bmp')]), |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
458 ('unknown decl', 'endif') |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
459 ] |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
460 self._run_check(html, expected) |
|
4ddbb756b602
#13576: add tests about the handling of (possibly broken) condcoms.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73609
diff
changeset
|
461 |
|
73289
8f9f490b4777
Make sure that the tolerant parser still parses valid HTML correctly.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73279
diff
changeset
|
462 |
|
73546
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
463 class AttributesStrictTestCase(TestCaseBase): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
464 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
465 def get_collector(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
466 return EventCollector(strict=True) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
467 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
468 def test_attr_syntax(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
469 output = [ |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
470 ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
471 ] |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
472 self._run_check("""<a b='v' c="v" d=v e>""", output) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
473 self._run_check("""<a b = 'v' c = "v" d = v e>""", output) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
474 self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
475 self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
476 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
477 def test_attr_values(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
478 self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
479 [("starttag", "a", [("b", "xxx\n\txxx"), |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
480 ("c", "yyy\t\nyyy"), |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
481 ("d", "\txyz\n")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
482 self._run_check("""<a b='' c="">""", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
483 [("starttag", "a", [("b", ""), ("c", "")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
484 # Regression test for SF patch #669683. |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
485 self._run_check("<e a=rgb(1,2,3)>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
486 [("starttag", "e", [("a", "rgb(1,2,3)")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
487 # Regression test for SF bug #921657. |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
488 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
489 "<a href=mailto:xyz@example.com>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
490 [("starttag", "a", [("href", "mailto:xyz@example.com")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
491 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
492 def test_attr_nonascii(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
493 # see issue 7311 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
494 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
495 "<img src=/foo/bar.png alt=\u4e2d\u6587>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
496 [("starttag", "img", [("src", "/foo/bar.png"), |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
497 ("alt", "\u4e2d\u6587")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
498 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
499 "<a title='\u30c6\u30b9\u30c8' href='\u30c6\u30b9\u30c8.html'>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
500 [("starttag", "a", [("title", "\u30c6\u30b9\u30c8"), |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
501 ("href", "\u30c6\u30b9\u30c8.html")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
502 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
503 '<a title="\u30c6\u30b9\u30c8" href="\u30c6\u30b9\u30c8.html">', |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
504 [("starttag", "a", [("title", "\u30c6\u30b9\u30c8"), |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
505 ("href", "\u30c6\u30b9\u30c8.html")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
506 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
507 def test_attr_entity_replacement(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
508 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
509 "<a b='&><"''>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
510 [("starttag", "a", [("b", "&><\"'")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
511 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
512 def test_attr_funky_names(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
513 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
514 "<a a.b='v' c:d=v e-f=v>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
515 [("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
516 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
517 def test_entityrefs_in_attributes(self): |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
518 self._run_check( |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
519 "<html foo='€&aa&unsupported;'>", |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
520 [("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])]) |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
521 |
|
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
522 |
|
73547
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
523 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
524 class AttributesTolerantTestCase(AttributesStrictTestCase): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
525 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
526 def get_collector(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
527 return EventCollector(strict=False) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
528 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
529 def test_attr_funky_names2(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
530 self._run_check( |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
531 "<a $><b $=%><c \=/>", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
532 [("starttag", "a", [("$", None)]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
533 ("starttag", "b", [("$", "%")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
534 ("starttag", "c", [("\\", "/")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
535 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
536 def test_entities_in_attribute_value(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
537 # see #1200313 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
538 for entity in ['&', '&', '&', '&']: |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
539 self._run_check('<a href="%s">' % entity, |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
540 [("starttag", "a", [("href", "&")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
541 self._run_check("<a href='%s'>" % entity, |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
542 [("starttag", "a", [("href", "&")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
543 self._run_check("<a href=%s>" % entity, |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
544 [("starttag", "a", [("href", "&")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
545 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
546 def test_malformed_attributes(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
547 # see #13357 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
548 html = ( |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
549 "<a href=test'style='color:red;bad1'>test - bad1</a>" |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
550 "<a href=test'+style='color:red;ba2'>test - bad2</a>" |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
551 "<a href=test' style='color:red;bad3'>test - bad3</a>" |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
552 "<a href = test' style='color:red;bad4' >test - bad4</a>" |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
553 ) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
554 expected = [ |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
555 ('starttag', 'a', [('href', "test'style='color:red;bad1'")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
556 ('data', 'test - bad1'), ('endtag', 'a'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
557 ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
558 ('data', 'test - bad2'), ('endtag', 'a'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
559 ('starttag', 'a', [('href', "test'\xa0style='color:red;bad3'")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
560 ('data', 'test - bad3'), ('endtag', 'a'), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
561 ('starttag', 'a', [('href', "test'\xa0style='color:red;bad4'")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
562 ('data', 'test - bad4'), ('endtag', 'a') |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
563 ] |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
564 self._run_check(html, expected) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
565 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
566 def test_malformed_adjacent_attributes(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
567 # see #12629 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
568 self._run_check('<x><y z=""o"" /></x>', |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
569 [('starttag', 'x', []), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
570 ('startendtag', 'y', [('z', ''), ('o""', None)]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
571 ('endtag', 'x')]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
572 self._run_check('<x><y z="""" /></x>', |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
573 [('starttag', 'x', []), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
574 ('startendtag', 'y', [('z', ''), ('""', None)]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
575 ('endtag', 'x')]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
576 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
577 # see #755670 for the following 3 tests |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
578 def test_adjacent_attributes(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
579 self._run_check('<a width="100%"cellspacing=0>', |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
580 [("starttag", "a", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
581 [("width", "100%"), ("cellspacing","0")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
582 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
583 self._run_check('<a id="foo"class="bar">', |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
584 [("starttag", "a", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
585 [("id", "foo"), ("class","bar")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
586 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
587 def test_missing_attribute_value(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
588 self._run_check('<a v=>', |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
589 [("starttag", "a", [("v", "")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
590 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
591 def test_javascript_attribute_value(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
592 self._run_check("<a href=javascript:popup('/popup/help.html')>", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
593 [("starttag", "a", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
594 [("href", "javascript:popup('/popup/help.html')")])]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
595 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
596 def test_end_tag_in_attribute_value(self): |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
597 # see #1745761 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
598 self._run_check("<a href='http://www.example.org/\">;'>spam</a>", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
599 [("starttag", "a", |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
600 [("href", "http://www.example.org/\">;")]), |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
601 ("data", "spam"), ("endtag", "a")]) |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
602 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
603 |
|
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
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(): |
|
73546
62d4dc5bb3ec
Group tests about attributes in a separate class.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73289
diff
changeset
|
606 support.run_unittest(HTMLParserStrictTestCase, HTMLParserTolerantTestCase, |
|
73547
16ed15ff0d7c
#1745761, #755670, #13357, #12629, #1200313: improve attribute handling in HTMLParser.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73546
diff
changeset
|
607 AttributesStrictTestCase, AttributesTolerantTestCase) |
|
20069
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 |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
610 if __name__ == "__main__": |
|
90a4f23abda7
Adapt to use the test_main() approach.
Fred Drake <fdrake@acm.org>
parents:
19687
diff
changeset
|
611 test_main() |
