From 4b0f20def3528469f3579445783d2d5db3f50c48 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 15 Oct 2005 16:41:53 +0000 Subject: Teach unquote() to handle unicode inputs --- Lib/test/test_urllib.py | 4 ++++ Lib/urllib.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 94f0f9e..4579c47 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -415,6 +415,10 @@ class UnquotingTests(unittest.TestCase): self.assertEqual(expect, result, "using unquote_plus(): %s != %s" % (expect, result)) + def test_unquote_with_unicode(self): + r = urllib.unquote(u'br%C3%BCckner_sapporo_20050930.doc') + self.assertEqual(r, u'br\xc3\xbcckner_sapporo_20050930.doc') + class urlencode_Tests(unittest.TestCase): """Tests for urlencode()""" diff --git a/Lib/urllib.py b/Lib/urllib.py index bc16be0..f00d02f 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -1061,6 +1061,8 @@ def unquote(s): res[i] = _hextochr[item[:2]] + item[2:] except KeyError: res[i] = '%' + item + except UnicodeDecodeError: + res[i] = unichr(int(item[:2], 16)) + item[2:] return "".join(res) def unquote_plus(s): -- cgit v0.12