]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Convert path components to unicode for consistency with get_argument().
authorBen Darnell <ben@bendarnell.com>
Sat, 28 May 2011 21:23:36 +0000 (14:23 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 28 May 2011 21:23:36 +0000 (14:23 -0700)
tornado/test/web_test.py
tornado/web.py

index 0d9171caab05318d44a59601236118d1b3ab8f24..ae2c23cf337a401e591a8f37aec25adda85e41af 100644 (file)
@@ -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"]}})
index ec90634d2adf47e27e60518ac3dc61f0adbdbd15..d631b15bc390019822510c7b072404900c79d052 100644 (file)
@@ -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,