From: Ben Darnell Date: Tue, 19 Oct 2010 19:28:47 +0000 (-0700) Subject: Add test case for encoding of request parameters and paths, X-Git-Tag: v1.2.0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7553f75130329446149085d877403164d3770e9;p=thirdparty%2Ftornado.git Add test case for encoding of request parameters and paths, in response to a mailing list thread that raised questions about handling of '%3F' and '?'. --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 372fc6872..fccca7dc1 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -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={'?': ['?']})) +