diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2013-05-01 16:20:00 +0300 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2013-05-01 16:20:00 +0300 |
commit | f6ca26fbffb689190da9dbe66df09c7d7e118616 (patch) | |
tree | cad09a0c76c4ad8547c01d2a7b170f278423dafa | |
parent | 8a42d601888e9f71e2c1fcfe93593c509f431c15 (diff) | |
parent | 8e596a765cf323cbd2ba31b15f2939f903d87913 (diff) | |
download | cpython-git-f6ca26fbffb689190da9dbe66df09c7d7e118616.tar.gz |
#17802: merge with 3.3.
-rw-r--r-- | Lib/html/parser.py | 1 | ||||
-rw-r--r-- | Lib/test/test_htmlparser.py | 14 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 18 insertions, 0 deletions
diff --git a/Lib/html/parser.py b/Lib/html/parser.py index 485f6fac6f..18f31152a3 100644 --- a/Lib/html/parser.py +++ b/Lib/html/parser.py @@ -251,6 +251,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;') @@ -62,6 +62,9 @@ Library - 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. |