]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix path parsing in HTTPServer.
authorBen Darnell <ben@bendarnell.com>
Thu, 10 May 2012 04:57:44 +0000 (21:57 -0700)
committerBen Darnell <ben@bendarnell.com>
Thu, 10 May 2012 04:57:44 +0000 (21:57 -0700)
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.

tornado/httpserver.py
tornado/test/httpserver_test.py

index e6fe996abd7a51ee050f21c64158a25522f70f73..5df8da3ecb7e4d5b6a68f61eaed4d0456a7cefd7 100644 (file)
@@ -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]
index 71134f1152130a4b8d82a275a78788efe49fd359..3b49a5026acb01d45234ca9976d2954e7e554f0f 100644 (file)
@@ -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):