(original) (raw)

changeset: 83587:20be90a3a714 parent: 83585:9ea84f006892 parent: 83586:9cb90c1a1a46 user: Ezio Melotti ezio.melotti@gmail.com date: Wed May 01 16:20:00 2013 +0300 files: Lib/html/parser.py Misc/NEWS description: #17802: merge with 3.3. diff -r 9ea84f006892 -r 20be90a3a714 Lib/html/parser.py --- a/Lib/html/parser.py Wed May 01 15:15:50 2013 +0200 +++ b/Lib/html/parser.py Wed May 01 16:20:00 2013 +0300 @@ -251,6 +251,7 @@ 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 -r 9ea84f006892 -r 20be90a3a714 Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py Wed May 01 15:15:50 2013 +0200 +++ b/Lib/test/test_htmlparser.py Wed May 01 16:20:00 2013 +0300 @@ -535,6 +535,20 @@ ] 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 -r 9ea84f006892 -r 20be90a3a714 Misc/NEWS --- a/Misc/NEWS Wed May 01 15:15:50 2013 +0200 +++ b/Misc/NEWS Wed May 01 16:20:00 2013 +0300 @@ -62,6 +62,9 @@ - Issue #14679: add an __all__ (that contains only HTMLParser) to html.parser. +- Issue #17802: Fix an UnboundLocalError in html.parser. Initial tests by + Thomas Barlow. + - Issue #17358: Modules loaded by imp.load_source() and load_compiled() (and by extention load_module()) now have a better chance of working when reloaded. /ezio.melotti@gmail.com