blob: b587ab80d5403a28035224cbb4000cae9aff101a [file] [log] [blame]
Fred Drakebd3090d2001-05-18 15:32:59 +00001"""Tests for HTMLParser.py."""
2
Mark Dickinsonf64dcf32008-05-21 13:51:18 +00003import html.parser
Fred Drake029acfb2001-08-20 21:24:19 +00004import pprint
Fred Drakebd3090d2001-05-18 15:32:59 +00005import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00006from test import support
Fred Drakebd3090d2001-05-18 15:32:59 +00007
8
Mark Dickinsonf64dcf32008-05-21 13:51:18 +00009class EventCollector(html.parser.HTMLParser):
Fred Drakebd3090d2001-05-18 15:32:59 +000010
R. David Murrayb579dba2010-12-03 04:06:39 +000011 def __init__(self, *args, **kw):
Fred Drakebd3090d2001-05-18 15:32:59 +000012 self.events = []
13 self.append = self.events.append
R. David Murrayb579dba2010-12-03 04:06:39 +000014 html.parser.HTMLParser.__init__(self, *args, **kw)
Fred Drakebd3090d2001-05-18 15:32:59 +000015
16 def get_events(self):
17 # Normalize the list of events so that buffer artefacts don't
18 # separate runs of contiguous characters.
19 L = []
20 prevtype = None
21 for event in self.events:
22 type = event[0]
23 if type == prevtype == "data":
24 L[-1] = ("data", L[-1][1] + event[1])
25 else:
26 L.append(event)
27 prevtype = type
28 self.events = L
29 return L
30
31 # structure markup
32
33 def handle_starttag(self, tag, attrs):
34 self.append(("starttag", tag, attrs))
35
36 def handle_startendtag(self, tag, attrs):
37 self.append(("startendtag", tag, attrs))
38
39 def handle_endtag(self, tag):
40 self.append(("endtag", tag))
41
42 # all other markup
43
44 def handle_comment(self, data):
45 self.append(("comment", data))
46
47 def handle_charref(self, data):
48 self.append(("charref", data))
49
50 def handle_data(self, data):
51 self.append(("data", data))
52
53 def handle_decl(self, data):
54 self.append(("decl", data))
55
56 def handle_entityref(self, data):
57 self.append(("entityref", data))
58
59 def handle_pi(self, data):
60 self.append(("pi", data))
61
Fred Drakec20a6982001-09-04 15:13:04 +000062 def unknown_decl(self, decl):
63 self.append(("unknown decl", decl))
64
Fred Drakebd3090d2001-05-18 15:32:59 +000065
66class EventCollectorExtra(EventCollector):
67
68 def handle_starttag(self, tag, attrs):
69 EventCollector.handle_starttag(self, tag, attrs)
70 self.append(("starttag_text", self.get_starttag_text()))
71
72
73class TestCaseBase(unittest.TestCase):
74
Ezio Melottic1e73c32011-11-01 18:57:15 +020075 def get_collector(self):
76 raise NotImplementedError
77
R. David Murrayb579dba2010-12-03 04:06:39 +000078 def _run_check(self, source, expected_events, collector=None):
79 if collector is None:
Ezio Melottic1e73c32011-11-01 18:57:15 +020080 collector = self.get_collector()
R. David Murrayb579dba2010-12-03 04:06:39 +000081 parser = collector
Fred Drakebd3090d2001-05-18 15:32:59 +000082 for s in source:
83 parser.feed(s)
Fred Drakebd3090d2001-05-18 15:32:59 +000084 parser.close()
Fred Drake029acfb2001-08-20 21:24:19 +000085 events = parser.get_events()
Fred Drakec20a6982001-09-04 15:13:04 +000086 if events != expected_events:
87 self.fail("received events did not match expected events\n"
88 "Expected:\n" + pprint.pformat(expected_events) +
89 "\nReceived:\n" + pprint.pformat(events))
Fred Drakebd3090d2001-05-18 15:32:59 +000090
91 def _run_check_extra(self, source, events):
R. David Murrayb579dba2010-12-03 04:06:39 +000092 self._run_check(source, events, EventCollectorExtra())
Fred Drakebd3090d2001-05-18 15:32:59 +000093
94 def _parse_error(self, source):
95 def parse(source=source):
Mark Dickinsonf64dcf32008-05-21 13:51:18 +000096 parser = html.parser.HTMLParser()
Fred Drakebd3090d2001-05-18 15:32:59 +000097 parser.feed(source)
98 parser.close()
Mark Dickinsonf64dcf32008-05-21 13:51:18 +000099 self.assertRaises(html.parser.HTMLParseError, parse)
Fred Drakebd3090d2001-05-18 15:32:59 +0000100
101
Ezio Melottic1e73c32011-11-01 18:57:15 +0200102class HTMLParserStrictTestCase(TestCaseBase):
103
104 def get_collector(self):
105 return EventCollector(strict=True)
Fred Drakebd3090d2001-05-18 15:32:59 +0000106
Fred Drake84bb9d82001-08-03 19:53:01 +0000107 def test_processing_instruction_only(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000108 self._run_check("<?processing instruction>", [
109 ("pi", "processing instruction"),
110 ])
Fred Drakefafd56f2003-04-17 22:19:26 +0000111 self._run_check("<?processing instruction ?>", [
112 ("pi", "processing instruction ?"),
113 ])
Fred Drakebd3090d2001-05-18 15:32:59 +0000114
Fred Drake84bb9d82001-08-03 19:53:01 +0000115 def test_simple_html(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000116 self._run_check("""
117<!DOCTYPE html PUBLIC 'foo'>
118<HTML>&entity;&#32;
119<!--comment1a
120-></foo><bar>&lt;<?pi?></foo<bar
121comment1b-->
122<Img sRc='Bar' isMAP>sample
123text
Fred Drake84bb9d82001-08-03 19:53:01 +0000124&#x201C;
Georg Brandld09def32006-03-09 13:27:14 +0000125<!--comment2a-- --comment2b--><!>
Fred Drakebd3090d2001-05-18 15:32:59 +0000126</Html>
127""", [
128 ("data", "\n"),
129 ("decl", "DOCTYPE html PUBLIC 'foo'"),
130 ("data", "\n"),
131 ("starttag", "html", []),
132 ("entityref", "entity"),
133 ("charref", "32"),
134 ("data", "\n"),
135 ("comment", "comment1a\n-></foo><bar>&lt;<?pi?></foo<bar\ncomment1b"),
136 ("data", "\n"),
137 ("starttag", "img", [("src", "Bar"), ("ismap", None)]),
138 ("data", "sample\ntext\n"),
Fred Drake84bb9d82001-08-03 19:53:01 +0000139 ("charref", "x201C"),
140 ("data", "\n"),
Fred Drakebd3090d2001-05-18 15:32:59 +0000141 ("comment", "comment2a-- --comment2b"),
142 ("data", "\n"),
143 ("endtag", "html"),
144 ("data", "\n"),
145 ])
146
Victor Stinnere021f4b2010-05-24 21:46:25 +0000147 def test_malformatted_charref(self):
148 self._run_check("<p>&#bad;</p>", [
149 ("starttag", "p", []),
150 ("data", "&#bad;"),
151 ("endtag", "p"),
152 ])
153
Fred Drake073148c2001-12-03 16:44:09 +0000154 def test_unclosed_entityref(self):
155 self._run_check("&entityref foo", [
156 ("entityref", "entityref"),
157 ("data", " foo"),
158 ])
159
Fred Drake029acfb2001-08-20 21:24:19 +0000160 def test_doctype_decl(self):
161 inside = """\
162DOCTYPE html [
163 <!ELEMENT html - O EMPTY>
164 <!ATTLIST html
Fred Drakec20a6982001-09-04 15:13:04 +0000165 version CDATA #IMPLIED
166 profile CDATA 'DublinCore'>
167 <!NOTATION datatype SYSTEM 'http://xml.python.org/notations/python-module'>
168 <!ENTITY myEntity 'internal parsed entity'>
169 <!ENTITY anEntity SYSTEM 'http://xml.python.org/entities/something.xml'>
170 <!ENTITY % paramEntity 'name|name|name'>
171 %paramEntity;
Fred Drake029acfb2001-08-20 21:24:19 +0000172 <!-- comment -->
173]"""
174 self._run_check("<!%s>" % inside, [
175 ("decl", inside),
176 ])
177
Fred Drake84bb9d82001-08-03 19:53:01 +0000178 def test_bad_nesting(self):
179 # Strangely, this *is* supposed to test that overlapping
180 # elements are allowed. HTMLParser is more geared toward
181 # lexing the input that parsing the structure.
Fred Drakebd3090d2001-05-18 15:32:59 +0000182 self._run_check("<a><b></a></b>", [
183 ("starttag", "a", []),
184 ("starttag", "b", []),
185 ("endtag", "a"),
186 ("endtag", "b"),
187 ])
188
Fred Drake029acfb2001-08-20 21:24:19 +0000189 def test_bare_ampersands(self):
190 self._run_check("this text & contains & ampersands &", [
191 ("data", "this text & contains & ampersands &"),
192 ])
193
194 def test_bare_pointy_brackets(self):
195 self._run_check("this < text > contains < bare>pointy< brackets", [
196 ("data", "this < text > contains < bare>pointy< brackets"),
197 ])
198
Fred Drake84bb9d82001-08-03 19:53:01 +0000199 def test_attr_syntax(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000200 output = [
201 ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
202 ]
203 self._run_check("""<a b='v' c="v" d=v e>""", output)
204 self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
205 self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
206 self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
207
Fred Drake84bb9d82001-08-03 19:53:01 +0000208 def test_attr_values(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000209 self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
210 [("starttag", "a", [("b", "xxx\n\txxx"),
211 ("c", "yyy\t\nyyy"),
212 ("d", "\txyz\n")])
213 ])
214 self._run_check("""<a b='' c="">""", [
215 ("starttag", "a", [("b", ""), ("c", "")]),
216 ])
Fred Drake0834d772003-03-14 16:21:57 +0000217 # Regression test for SF patch #669683.
218 self._run_check("<e a=rgb(1,2,3)>", [
219 ("starttag", "e", [("a", "rgb(1,2,3)")]),
220 ])
Tim Peters27f88362004-07-08 04:22:35 +0000221 # Regression test for SF bug #921657.
Andrew M. Kuchlingb7d8ce02004-06-05 15:31:45 +0000222 self._run_check("<a href=mailto:xyz@example.com>", [
223 ("starttag", "a", [("href", "mailto:xyz@example.com")]),
224 ])
Fred Drakebd3090d2001-05-18 15:32:59 +0000225
Ezio Melotti2e3607c2011-04-07 22:03:31 +0300226 def test_attr_nonascii(self):
227 # see issue 7311
228 self._run_check("<img src=/foo/bar.png alt=\u4e2d\u6587>", [
229 ("starttag", "img", [("src", "/foo/bar.png"),
230 ("alt", "\u4e2d\u6587")]),
231 ])
232 self._run_check("<a title='\u30c6\u30b9\u30c8' "
233 "href='\u30c6\u30b9\u30c8.html'>", [
234 ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
235 ("href", "\u30c6\u30b9\u30c8.html")]),
236 ])
237 self._run_check('<a title="\u30c6\u30b9\u30c8" '
238 'href="\u30c6\u30b9\u30c8.html">', [
239 ("starttag", "a", [("title", "\u30c6\u30b9\u30c8"),
240 ("href", "\u30c6\u30b9\u30c8.html")]),
241 ])
242
Fred Drake84bb9d82001-08-03 19:53:01 +0000243 def test_attr_entity_replacement(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000244 self._run_check("""<a b='&amp;&gt;&lt;&quot;&apos;'>""", [
245 ("starttag", "a", [("b", "&><\"'")]),
246 ])
247
Fred Drake84bb9d82001-08-03 19:53:01 +0000248 def test_attr_funky_names(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000249 self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
250 ("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
251 ])
252
Fred Drakec20a6982001-09-04 15:13:04 +0000253 def test_illegal_declarations(self):
Fred Drake7cf613d2001-09-04 16:26:03 +0000254 self._parse_error('<!spacer type="block" height="25">')
Fred Drakec20a6982001-09-04 15:13:04 +0000255
Fred Drake84bb9d82001-08-03 19:53:01 +0000256 def test_starttag_end_boundary(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000257 self._run_check("""<a b='<'>""", [("starttag", "a", [("b", "<")])])
258 self._run_check("""<a b='>'>""", [("starttag", "a", [("b", ">")])])
259
Fred Drake84bb9d82001-08-03 19:53:01 +0000260 def test_buffer_artefacts(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000261 output = [("starttag", "a", [("b", "<")])]
262 self._run_check(["<a b='<'>"], output)
263 self._run_check(["<a ", "b='<'>"], output)
264 self._run_check(["<a b", "='<'>"], output)
265 self._run_check(["<a b=", "'<'>"], output)
266 self._run_check(["<a b='<", "'>"], output)
267 self._run_check(["<a b='<'", ">"], output)
268
269 output = [("starttag", "a", [("b", ">")])]
270 self._run_check(["<a b='>'>"], output)
271 self._run_check(["<a ", "b='>'>"], output)
272 self._run_check(["<a b", "='>'>"], output)
273 self._run_check(["<a b=", "'>'>"], output)
274 self._run_check(["<a b='>", "'>"], output)
275 self._run_check(["<a b='>'", ">"], output)
276
Fred Drake75d9a622004-09-08 22:57:01 +0000277 output = [("comment", "abc")]
278 self._run_check(["", "<!--abc-->"], output)
279 self._run_check(["<", "!--abc-->"], output)
280 self._run_check(["<!", "--abc-->"], output)
281 self._run_check(["<!-", "-abc-->"], output)
282 self._run_check(["<!--", "abc-->"], output)
283 self._run_check(["<!--a", "bc-->"], output)
284 self._run_check(["<!--ab", "c-->"], output)
285 self._run_check(["<!--abc", "-->"], output)
286 self._run_check(["<!--abc-", "->"], output)
287 self._run_check(["<!--abc--", ">"], output)
288 self._run_check(["<!--abc-->", ""], output)
289
Fred Drake84bb9d82001-08-03 19:53:01 +0000290 def test_starttag_junk_chars(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000291 self._parse_error("</>")
292 self._parse_error("</$>")
293 self._parse_error("</")
294 self._parse_error("</a")
Fred Drakebd3090d2001-05-18 15:32:59 +0000295 self._parse_error("<a<a>")
296 self._parse_error("</a<a>")
Fred Drakebd3090d2001-05-18 15:32:59 +0000297 self._parse_error("<!")
298 self._parse_error("<a $>")
299 self._parse_error("<a")
300 self._parse_error("<a foo='bar'")
301 self._parse_error("<a foo='bar")
302 self._parse_error("<a foo='>'")
303 self._parse_error("<a foo='>")
304 self._parse_error("<a foo=>")
305
Fred Drake84bb9d82001-08-03 19:53:01 +0000306 def test_declaration_junk_chars(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000307 self._parse_error("<!DOCTYPE foo $ >")
308
Fred Drake84bb9d82001-08-03 19:53:01 +0000309 def test_startendtag(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000310 self._run_check("<p/>", [
311 ("startendtag", "p", []),
312 ])
313 self._run_check("<p></p>", [
314 ("starttag", "p", []),
315 ("endtag", "p"),
316 ])
317 self._run_check("<p><img src='foo' /></p>", [
318 ("starttag", "p", []),
319 ("startendtag", "img", [("src", "foo")]),
320 ("endtag", "p"),
321 ])
322
Fred Drake84bb9d82001-08-03 19:53:01 +0000323 def test_get_starttag_text(self):
Fred Drakebd3090d2001-05-18 15:32:59 +0000324 s = """<foo:bar \n one="1"\ttwo=2 >"""
325 self._run_check_extra(s, [
326 ("starttag", "foo:bar", [("one", "1"), ("two", "2")]),
327 ("starttag_text", s)])
328
Fred Drake84bb9d82001-08-03 19:53:01 +0000329 def test_cdata_content(self):
Ezio Melotti7de56f62011-11-01 14:12:22 +0200330 contents = [
331 '<!-- not a comment --> &not-an-entity-ref;',
332 "<not a='start tag'>",
333 '<a href="" /> <p> <span></span>',
334 'foo = "</scr" + "ipt>";',
335 'foo = "</SCRIPT" + ">";',
336 'foo = <\n/script> ',
337 '<!-- document.write("</scr" + "ipt>"); -->',
338 ('\n//<![CDATA[\n'
339 'document.write(\'<s\'+\'cript type="text/javascript" '
340 'src="http://www.example.org/r=\'+new '
341 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'),
342 '\n<!-- //\nvar foo = 3.14;\n// -->\n',
343 'foo = "</sty" + "le>";',
344 '<!-- \u2603 -->',
345 # these two should be invalid according to the HTML 5 spec,
346 # section 8.1.2.2
347 #'foo = </\nscript>',
348 #'foo = </ script>',
349 ]
350 elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style']
351 for content in contents:
352 for element in elements:
353 element_lower = element.lower()
354 s = '<{element}>{content}</{element}>'.format(element=element,
355 content=content)
356 self._run_check(s, [("starttag", element_lower, []),
357 ("data", content),
358 ("endtag", element_lower)])
359
Fred Drakebd3090d2001-05-18 15:32:59 +0000360
Guido van Rossumd8faa362007-04-27 19:54:29 +0000361 def test_entityrefs_in_attributes(self):
Ezio Melottic1e73c32011-11-01 18:57:15 +0200362 self._run_check("<html foo='&euro;&amp;&#97;&#x61;&unsupported;'>",
363 [("starttag", "html", [("foo", "\u20AC&aa&unsupported;")])])
Guido van Rossumd8faa362007-04-27 19:54:29 +0000364
Fred Drakebd3090d2001-05-18 15:32:59 +0000365
Ezio Melottic1e73c32011-11-01 18:57:15 +0200366class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
R. David Murrayb579dba2010-12-03 04:06:39 +0000367
Ezio Melottib9a48f72011-11-01 15:00:59 +0200368 def get_collector(self):
369 return EventCollector(strict=False)
R. David Murrayb579dba2010-12-03 04:06:39 +0000370
371 def test_tolerant_parsing(self):
372 self._run_check('<html <html>te>>xt&a<<bc</a></html>\n'
373 '<img src="URL><//img></html</html>', [
374 ('data', '<html '),
375 ('starttag', 'html', []),
376 ('data', 'te>>xt'),
377 ('entityref', 'a'),
378 ('data', '<<bc'),
379 ('endtag', 'a'),
380 ('endtag', 'html'),
381 ('data', '\n<img src="URL><//img></html'),
Ezio Melottic1e73c32011-11-01 18:57:15 +0200382 ('endtag', 'html')])
R. David Murrayb579dba2010-12-03 04:06:39 +0000383
Ezio Melotti18b0e5b2011-11-01 14:42:54 +0200384 def test_with_unquoted_attributes(self):
Ezio Melottib9a48f72011-11-01 15:00:59 +0200385 # see #12008
Ezio Melotti18b0e5b2011-11-01 14:42:54 +0200386 html = ("<html><body bgcolor=d0ca90 text='181008'>"
387 "<table cellspacing=0 cellpadding=1 width=100% ><tr>"
388 "<td align=left><font size=-1>"
389 "- <a href=/rabota/><span class=en> software-and-i</span></a>"
390 "- <a href='/1/'><span class=en> library</span></a></table>")
391 expected = [
392 ('starttag', 'html', []),
393 ('starttag', 'body', [('bgcolor', 'd0ca90'), ('text', '181008')]),
394 ('starttag', 'table',
395 [('cellspacing', '0'), ('cellpadding', '1'), ('width', '100%')]),
396 ('starttag', 'tr', []),
397 ('starttag', 'td', [('align', 'left')]),
398 ('starttag', 'font', [('size', '-1')]),
399 ('data', '- '), ('starttag', 'a', [('href', '/rabota/')]),
400 ('starttag', 'span', [('class', 'en')]), ('data', ' software-and-i'),
401 ('endtag', 'span'), ('endtag', 'a'),
402 ('data', '- '), ('starttag', 'a', [('href', '/1/')]),
403 ('starttag', 'span', [('class', 'en')]), ('data', ' library'),
404 ('endtag', 'span'), ('endtag', 'a'), ('endtag', 'table')
405 ]
Ezio Melottic1e73c32011-11-01 18:57:15 +0200406 self._run_check(html, expected)
Ezio Melotti18b0e5b2011-11-01 14:42:54 +0200407
R. David Murrayb579dba2010-12-03 04:06:39 +0000408 def test_comma_between_attributes(self):
409 self._run_check('<form action="/xxx.php?a=1&amp;b=2&amp", '
410 'method="post">', [
411 ('starttag', 'form',
412 [('action', '/xxx.php?a=1&b=2&amp'),
Ezio Melottic1e73c32011-11-01 18:57:15 +0200413 ('method', 'post')])])
R. David Murrayb579dba2010-12-03 04:06:39 +0000414
415 def test_weird_chars_in_unquoted_attribute_values(self):
416 self._run_check('<form action=bogus|&#()value>', [
417 ('starttag', 'form',
Ezio Melottic1e73c32011-11-01 18:57:15 +0200418 [('action', 'bogus|&#()value')])])
R. David Murrayb579dba2010-12-03 04:06:39 +0000419
Ezio Melottib9a48f72011-11-01 15:00:59 +0200420 def test_correct_detection_of_start_tags(self):
421 # see #13273
Ezio Melottif50ffa92011-10-28 13:21:09 +0300422 html = ('<div style="" ><b>The <a href="some_url">rain</a> '
423 '<br /> in <span>Spain</span></b></div>')
424 expected = [
425 ('starttag', 'div', [('style', '')]),
426 ('starttag', 'b', []),
427 ('data', 'The '),
428 ('starttag', 'a', [('href', 'some_url')]),
429 ('data', 'rain'),
430 ('endtag', 'a'),
431 ('data', ' '),
432 ('startendtag', 'br', []),
433 ('data', ' in '),
434 ('starttag', 'span', []),
435 ('data', 'Spain'),
436 ('endtag', 'span'),
437 ('endtag', 'b'),
438 ('endtag', 'div')
439 ]
Ezio Melottic1e73c32011-11-01 18:57:15 +0200440 self._run_check(html, expected)
Ezio Melottif50ffa92011-10-28 13:21:09 +0300441
Ezio Melottif50ffa92011-10-28 13:21:09 +0300442 html = '<div style="", foo = "bar" ><b>The <a href="some_url">rain</a>'
443 expected = [
444 ('starttag', 'div', [('style', ''), ('foo', 'bar')]),
445 ('starttag', 'b', []),
446 ('data', 'The '),
447 ('starttag', 'a', [('href', 'some_url')]),
448 ('data', 'rain'),
449 ('endtag', 'a'),
450 ]
Ezio Melottic1e73c32011-11-01 18:57:15 +0200451 self._run_check(html, expected)
Ezio Melottif50ffa92011-10-28 13:21:09 +0300452
Senthil Kumaran164540f2010-12-28 15:55:16 +0000453 def test_unescape_function(self):
454 p = html.parser.HTMLParser()
455 self.assertEqual(p.unescape('&#bad;'),'&#bad;')
456 self.assertEqual(p.unescape('&#0038;'),'&')
Ezio Melottid9e0b062011-09-05 17:11:06 +0300457 # see #12888
458 self.assertEqual(p.unescape('&#123; ' * 1050), '{ ' * 1050)
R. David Murrayb579dba2010-12-03 04:06:39 +0000459
Ezio Melottic1e73c32011-11-01 18:57:15 +0200460
Fred Drakee8220492001-09-24 20:19:08 +0000461def test_main():
Ezio Melottic1e73c32011-11-01 18:57:15 +0200462 support.run_unittest(HTMLParserStrictTestCase, HTMLParserTolerantTestCase)
Fred Drakee8220492001-09-24 20:19:08 +0000463
464
465if __name__ == "__main__":
466 test_main()