From: Ezio Melotti Date: Wed, 1 May 2013 13:18:25 +0000 (+0300) Subject: #17802: Fix an UnboundLocalError in html.parser. Initial tests by Thomas Barlow. X-Git-Tag: v3.3.2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e596a765cf323cbd2ba31b15f2939f903d87913;p=python #17802: Fix an UnboundLocalError in html.parser. Initial tests by Thomas Barlow. --- diff --git a/Lib/html/parser.py b/Lib/html/parser.py index f8ac82834a..60a322a949 100644 --- a/Lib/html/parser.py +++ b/Lib/html/parser.py @@ -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) diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py index c5d878dca5..b15b6fd4c6 100644 --- a/Lib/test/test_htmlparser.py +++ b/Lib/test/test_htmlparser.py @@ -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;') diff --git a/Misc/NEWS b/Misc/NEWS index 10f00a466c..465ca10ff0 100644 --- 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.