From: Ben Darnell Date: Sat, 28 May 2011 21:23:36 +0000 (-0700) Subject: Convert path components to unicode for consistency with get_argument(). X-Git-Tag: v2.0.0~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e36c9b462e5983ed07798a71d6cb9ba5564038dd;p=thirdparty%2Ftornado.git Convert path components to unicode for consistency with get_argument(). --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 0d9171caa..ae2c23cf3 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -148,7 +148,18 @@ class ConnectionCloseTest(AsyncHTTPTestCase, LogTrapTestCase): class EchoHandler(RequestHandler): def get(self, path): - self.write(dict(path=path, args=self.request.arguments)) + # Type checks: web.py interfaces convert arguments to unicode + # strings. In httpserver.py (i.e. self.request.arguments), + # they're left as the native str type. + for key in self.request.arguments: + assert type(key) == type(""), repr(key) + for value in self.request.arguments[key]: + assert type(value) == type(""), repr(value) + for value in self.get_arguments(key): + assert type(value) == unicode, repr(value) + assert type(path) == unicode, repr(path) + self.write(dict(path=path, + args=self.request.arguments)) class RequestEncodingTest(AsyncHTTPTestCase, LogTrapTestCase): def get_app(self): @@ -161,3 +172,8 @@ class RequestEncodingTest(AsyncHTTPTestCase, LogTrapTestCase): self.assertEqual(json_decode(self.fetch('/%3F?%3F=%3F').body), dict(path='?', args={'?': ['?']})) + def test_path_encoding(self): + # Path components and query arguments should be decoded the same way + self.assertEqual(json_decode(self.fetch('/%C3%A9?arg=%C3%A9').body), + {u"path":u"\u00e9", + u"args": {u"arg": [u"\u00e9"]}}) diff --git a/tornado/web.py b/tornado/web.py index ec90634d2..d631b15bc 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1202,7 +1202,7 @@ class Application(object): # unmatched optional groups correctly def unquote(s): if s is None: return s - return urllib.unquote(s) + return _unicode(urllib.unquote(s)) handler = spec.handler_class(self, request, **spec.kwargs) # Pass matched groups to the handler. Since # match.groups() includes both named and unnamed groups,