Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 tornadoweb#509.
  • Loading branch information
bdarnell committed May 10, 2012
1 parent 28590fc commit 25f4990
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tornado/httpserver.py
Expand Up @@ -391,10 +391,8 @@ def __init__(self, method, uri, version="HTTP/1.0", headers=None,
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]
Expand Down
9 changes: 9 additions & 0 deletions tornado/test/httpserver_test.py
Expand Up @@ -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):
Expand All @@ -324,6 +325,14 @@ def test_types(self):
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):
Expand Down

0 comments on commit 25f4990

Please sign in to comment.