]> granicus.if.org Git - python/commitdiff
#17802: Fix an UnboundLocalError in html.parser. Initial tests by Thomas Barlow.
authorEzio Melotti <ezio.melotti@gmail.com>
Wed, 1 May 2013 13:18:25 +0000 (16:18 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Wed, 1 May 2013 13:18:25 +0000 (16:18 +0300)
Lib/html/parser.py
Lib/test/test_htmlparser.py
Misc/NEWS

index f8ac82834a3e200fe707e818b1260e2417bcf660..60a322a9494d9df2c3fb0122c8ac63dfaa1159a3 100644 (file)
@@ -249,6 +249,7 @@ class HTMLParser(_markupbase.ParserBase):
                         if self.strict:
                             self.error("EOF in middle of entity or char ref")
                         else:
+                            k = match.end()
                             if k <= i:
                                 k = n
                             i = self.updatepos(i, i + 1)
index c5d878dca597809e156b95d8316a71d6b4a68e9f..b15b6fd4c6c0d0f8e472db770b33b59b31d26afa 100644 (file)
@@ -535,6 +535,20 @@ class HTMLParserTolerantTestCase(HTMLParserStrictTestCase):
         ]
         self._run_check(html, expected)
 
+    def test_EOF_in_charref(self):
+        # see #17802
+        # This test checks that the UnboundLocalError reported in the issue
+        # is not raised, however I'm not sure the returned values are correct.
+        # Maybe HTMLParser should use self.unescape for these
+        data = [
+            ('a&', [('data', 'a&')]),
+            ('a&b', [('data', 'ab')]),
+            ('a&b ', [('data', 'a'), ('entityref', 'b'), ('data', ' ')]),
+            ('a&b;', [('data', 'a'), ('entityref', 'b')]),
+        ]
+        for html, expected in data:
+            self._run_check(html, expected)
+
     def test_unescape_function(self):
         p = self.get_collector()
         self.assertEqual(p.unescape('&#bad;'),'&#bad;')
index 10f00a466c14b9c4693b67ebd8e9472a50850e93..465ca10ff014d477876c9d37c16bfc5312fd876f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #17802: Fix an UnboundLocalError in html.parser.  Initial tests by
+  Thomas Barlow.
+
 - Issue #17192: Restore the patch for Issue #11729 which was ommitted in
   3.3.1 when updating the bundled version of libffi used by ctypes.  Update
   many libffi files that were missed in 3.3.1's update to libffi-3.0.13.