]> granicus.if.org Git - python/commitdiff
#20288: fix handling of invalid numeric charrefs in HTMLParser.
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 1 Feb 2014 19:20:22 +0000 (21:20 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 1 Feb 2014 19:20:22 +0000 (21:20 +0200)
Lib/HTMLParser.py
Lib/test/test_htmlparser.py
Misc/NEWS

index 5a55e264afe845fca00c5399b2a69dcb581747dd..3f97830a9a0d1167e82b4615035eca7e702b7b11 100644 (file)
@@ -195,9 +195,9 @@ class HTMLParser(markupbase.ParserBase):
                     i = self.updatepos(i, k)
                     continue
                 else:
-                    if ";" in rawdata[i:]: #bail by consuming &#
-                        self.handle_data(rawdata[0:2])
-                        i = self.updatepos(i, 2)
+                    if ";" in rawdata[i:]:  # bail by consuming '&#'
+                        self.handle_data(rawdata[i:i+2])
+                        i = self.updatepos(i, i+2)
                     break
             elif startswith('&', i):
                 match = entityref.match(rawdata, i)
index 6a0e461829ee1fe629e18bee70fa3c481f235a71..cde2bd23b74f9b39254a6557b8bdd30d40d26035 100644 (file)
@@ -394,6 +394,12 @@ text
             ("data", "&#bad;"),
             ("endtag", "p"),
         ])
+        # add the [] as a workaround to avoid buffering (see #20288)
+        self._run_check(["<div>&#bad;</div>"], [
+            ("starttag", "div", []),
+            ("data", "&#bad;"),
+            ("endtag", "div"),
+        ])
 
     def test_unescape_function(self):
         parser = HTMLParser.HTMLParser()
index 67423709d98fe7f6d4342ac976ffbc39a0fead78..ec12fbef9ac32e5cc634f6cb6869776971d9e937 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #20288: fix handling of invalid numeric charrefs in HTMLParser.
+
 - Issue #19456: ntpath.join() now joins relative paths correctly when a drive
   is present.