r79492 - in python/branches/release26-maint: Lib/test/test_urllib.py Lib/urllib.py Lib/urlparse.py
![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: senthil.kumaran Date: Mon Mar 29 21:30:44 2010 New Revision: 79492 Log: Merged revisions 79047 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79047 | senthil.kumaran | 2010-03-18 17:44:15 +0530 (Thu, 18 Mar 2010) | 3 lines Fix for Issue8135 - urllib.unquote to support mixed percent escapes ........ Modified: python/branches/release26-maint/ (props changed) python/branches/release26-maint/Lib/test/test_urllib.py python/branches/release26-maint/Lib/urllib.py python/branches/release26-maint/Lib/urlparse.py Modified: python/branches/release26-maint/Lib/test/test_urllib.py ============================================================================== --- python/branches/release26-maint/Lib/test/test_urllib.py (original) +++ python/branches/release26-maint/Lib/test/test_urllib.py Mon Mar 29 21:30:44 2010 @@ -440,6 +440,32 @@ "using unquote(): not all characters escaped: " "%s" % result) + def test_unquoting_badpercent(self): + # Test unquoting on bad percent-escapes + given = '%xab' + expect = given + result = urllib.unquote(given) + self.assertEqual(expect, result, "using unquote(): %r != %r" + % (expect, result)) + given = '%x' + expect = given + result = urllib.unquote(given) + self.assertEqual(expect, result, "using unquote(): %r != %r" + % (expect, result)) + given = '%' + expect = given + result = urllib.unquote(given) + self.assertEqual(expect, result, "using unquote(): %r != %r" + % (expect, result)) + + def test_unquoting_mixed_case(self): + # Test unquoting on mixed-case hex digits in the percent-escapes + given = '%Ab%eA' + expect = '\xab\xea' + result = urllib.unquote(given) + self.assertEqual(expect, result, "using unquote(): %r != %r" + % (expect, result)) + def test_unquoting_parts(self): # Make sure unquoting works when have non-quoted characters # interspersed Modified: python/branches/release26-maint/Lib/urllib.py ============================================================================== --- python/branches/release26-maint/Lib/urllib.py (original) +++ python/branches/release26-maint/Lib/urllib.py Mon Mar 29 21:30:44 2010 @@ -1162,8 +1162,8 @@ if match: return match.group(1, 2) return attr, None -_hextochr = dict(('%02x' % i, chr(i)) for i in range(256)) -_hextochr.update(('%02X' % i, chr(i)) for i in range(256)) +_hexdig = '0123456789ABCDEFabcdef' +_hextochr = dict((a+b, chr(int(a+b,16))) for a in _hexdig for b in _hexdig) def unquote(s): """unquote('abc%20def') -> 'abc def'.""" Modified: python/branches/release26-maint/Lib/urlparse.py ============================================================================== --- python/branches/release26-maint/Lib/urlparse.py (original) +++ python/branches/release26-maint/Lib/urlparse.py Mon Mar 29 21:30:44 2010 @@ -272,8 +272,9 @@ # Cannot use directly from urllib as it would create circular reference. # urllib uses urlparse methods ( urljoin) -_hextochr = dict(('%02x' % i, chr(i)) for i in range(256)) -_hextochr.update(('%02X' % i, chr(i)) for i in range(256)) + +_hexdig = '0123456789ABCDEFabcdef' +_hextochr = dict((a+b, chr(int(a+b,16))) for a in _hexdig for b in _hexdig) def unquote(s): """unquote('abc%20def') -> 'abc def'."""
participants (1)
-
senthil.kumaran