(original) (raw)
changeset: 69160:7d4dea76c476 branch: 2.7 parent: 69153:c10d55c51d81 user: Ezio Melotti date: Tue Apr 05 20:40:52 2011 +0300 files: Lib/HTMLParser.py Lib/test/test_htmlparser.py Misc/NEWS description: #7311: fix HTMLParser to accept non-ASCII attribute values. diff -r c10d55c51d81 -r 7d4dea76c476 Lib/HTMLParser.py --- a/Lib/HTMLParser.py Tue Apr 05 15:24:34 2011 +0200 +++ b/Lib/HTMLParser.py Tue Apr 05 20:40:52 2011 +0300 @@ -26,7 +26,7 @@ tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*') attrfind = re.compile( r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' - r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]*))?') + r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?') locatestarttagend = re.compile(r""" <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name diff -r c10d55c51d81 -r 7d4dea76c476 Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py Tue Apr 05 15:24:34 2011 +0200 +++ b/Lib/test/test_htmlparser.py Tue Apr 05 20:40:52 2011 +0300 @@ -208,6 +208,23 @@ ("starttag", "a", [("href", "mailto:xyz@example.com")]), ]) + def test_attr_nonascii(self): + # see issue 7311 + self._run_check(u"", [ + ("starttag", "img", [("src", "/foo/bar.png"), + ("alt", u"\u4e2d\u6587")]), + ]) + self._run_check(u"", [ + ("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"), + ("href", u"\u30c6\u30b9\u30c8.html")]), + ]) + self._run_check(u'', [ + ("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"), + ("href", u"\u30c6\u30b9\u30c8.html")]), + ]) + def test_attr_entity_replacement(self): self._run_check("""""", [ ("starttag", "a", [("b", "&><\"'")]), diff -r c10d55c51d81 -r 7d4dea76c476 Misc/NEWS --- a/Misc/NEWS Tue Apr 05 15:24:34 2011 +0200 +++ b/Misc/NEWS Tue Apr 05 20:40:52 2011 +0300 @@ -47,6 +47,8 @@ Library ------- +- Issue #7311: fix HTMLParser to accept non-ASCII attribute values. + - Issue #10963: Ensure that subprocess.communicate() never raises EPIPE. - Issue #11662: Make urllib and urllib2 ignore redirections if the