From: Ben Darnell Date: Thu, 10 May 2012 04:57:44 +0000 (-0700) Subject: Fix path parsing in HTTPServer. X-Git-Tag: v2.3.0~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25f499004301846a9cb5c8e2c30692c64430acd1;p=thirdparty%2Ftornado.git Fix path parsing in HTTPServer. urlparse.urlsplit expects a full url, but we were using it for a bare path. This mostly worked but would parse paths beginning with "//" incorrectly. Fortunately all we really need to do is split the path on "?". Closes #509. --- diff --git a/tornado/httpserver.py b/tornado/httpserver.py index e6fe996ab..5df8da3ec 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -391,10 +391,8 @@ class HTTPRequest(object): self._start_time = time.time() self._finish_time = None - scheme, netloc, path, query, fragment = urlparse.urlsplit(native_str(uri)) - self.path = path - self.query = query - arguments = parse_qs_bytes(query) + self.path, sep, self.query = uri.partition('?') + arguments = parse_qs_bytes(self.query) self.arguments = {} for name, values in arguments.iteritems(): values = [v for v in values if v] diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index 71134f115..3b49a5026 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -307,6 +307,7 @@ class HTTPServerTest(AsyncHTTPTestCase, LogTrapTestCase): def get_app(self): return Application([("/echo", EchoHandler), ("/typecheck", TypeCheckHandler), + ("//doubleslash", EchoHandler), ]) def test_query_string_encoding(self): @@ -324,6 +325,14 @@ class HTTPServerTest(AsyncHTTPTestCase, LogTrapTestCase): data = json_decode(response.body) self.assertEqual(data, {}) + def test_double_slash(self): + # urlparse.urlsplit (which tornado.httpserver used to use + # incorrectly) would parse paths beginning with "//" as + # protocol-relative urls. + response = self.fetch("//doubleslash") + self.assertEqual(200, response.code) + self.assertEqual(json_decode(response.body), {}) + class XHeaderTest(HandlerBaseTestCase): class Handler(RequestHandler):