New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] URL parssing error in the web server #489

Closed
morgan-del opened this Issue Sep 3, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@morgan-del
Contributor

morgan-del commented Sep 3, 2015

If you run this simple server example :

import asyncio
from aiohttp import web

@asyncio.coroutine
def handle(request):
    return webResponse(body=request.path.encode('utf8'))

@asyncio.coroutine
def init(loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', '/', handle)
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 5555)
    return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))

try:
    loop.run_forever()
except KeyboardInterrupt:
    pass

The following requests will get a 200 OK with the considered path as content :

$ curl -X GET http://127.0.0.1:5555///
/
$ curl -X GET http://127.0.0.1:555//foo/
/

As you can see, the path of the URL is not well parsed.

This bug resides in the _splitted_path non-data descriptor which uses urlsplit on a path rather than a full URL. The consequence is a second segment interpreted as a network location if the first one is empty.

I've not quite investigated a fix at the moment, but _splitted_path only being used by raw_path and query_string seems to be a plea to use a fake scheme and netloc for urlsplit to behave the expected way.

@asvetlov asvetlov added the bug label Sep 3, 2015

@asvetlov

This comment has been minimized.

Member

asvetlov commented Sep 3, 2015

I'll take a look

@asvetlov asvetlov self-assigned this Sep 3, 2015

@asvetlov asvetlov added this to the 0.18 milestone Sep 3, 2015

@asvetlov asvetlov closed this in 430af0a Sep 4, 2015

asvetlov added a commit that referenced this issue Sep 4, 2015

Merge pull request #493 from morgan-del/url-parsing-bug
Fix #489 : properly parse URL's path

asvetlov added a commit that referenced this issue Sep 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment