]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add test case for encoding of request parameters and paths,
authorBen Darnell <ben@bendarnell.com>
Tue, 19 Oct 2010 19:28:47 +0000 (12:28 -0700)
committerBen Darnell <ben@bendarnell.com>
Tue, 19 Oct 2010 19:28:47 +0000 (12:28 -0700)
in response to a mailing list thread that raised questions about
handling of '%3F' and '?'.

tornado/test/web_test.py

index 372fc68724e43b99d961d406e1b1c04655710041..fccca7dc1d8a022f887b214fa12c38b136cb3fce 100644 (file)
@@ -1,3 +1,4 @@
+from tornado.escape import json_decode
 from tornado.iostream import IOStream
 from tornado.testing import LogTrapTestCase, AsyncHTTPTestCase
 from tornado.web import RequestHandler, _O, authenticated, Application, asynchronous
@@ -113,3 +114,19 @@ class ConnectionCloseTest(AsyncHTTPTestCase, LogTrapTestCase):
     def on_connection_close(self):
         logging.info('connection closed')
         self.stop()
+
+class EchoHandler(RequestHandler):
+    def get(self, path):
+        self.write(dict(path=path, args=self.request.arguments))
+
+class RequestEncodingTest(AsyncHTTPTestCase, LogTrapTestCase):
+    def get_app(self):
+        return Application([("/(.*)", EchoHandler)])
+
+    def test_question_mark(self):
+        # Ensure that url-encoded question marks are handled properly
+        self.assertEqual(json_decode(self.fetch('/%3F').body),
+                         dict(path='?', args={}))
+        self.assertEqual(json_decode(self.fetch('/%3F?%3F=%3F').body),
+                         dict(path='?', args={'?': ['?']}))
+