Skip to content
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

Do not use translated path #3051

Merged
merged 2 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/3051.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make redirect with `normalize_path_middleware` work when using url encoded paths.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Vladyslav Bondar
W. Trevor King
Will McGugan
Willem de Groot
William Grzybowski
Wilson Ong
Wei Lin
Weiwei Wang
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def impl(request, handler):
resolves, request = await _check_request_resolves(
request, path)
if resolves:
raise redirect_class(request.path + query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if request.path can be replaced with request.raw_path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats the same as path, no? request.raw_path is being used above to populate paths_to_check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It is the percent encoded canonical path representation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thats exactly the issue I am solving here, and its passing all the tests so I dont get it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So replace the call please

raise redirect_class(request.raw_path)

return await handler(request)

Expand Down
10 changes: 8 additions & 2 deletions tests/test_web_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def wrapper(extra_middlewares):
'GET', '/resource1/a/b', handler)
app.router.add_route(
'GET', '/resource2/a/b/', handler)
app.router.add_route(
'GET', '/resource2/a/b%2Fc/', handler)
app.middlewares.extend(extra_middlewares)
return aiohttp_client(app, server_kwargs={'skip_url_asserts': True})
return wrapper
Expand All @@ -101,7 +103,9 @@ class TestNormalizePathMiddleware:
('/resource1?p1=1&p2=2', 200),
('/resource1/?p1=1&p2=2', 404),
('/resource2?p1=1&p2=2', 200),
('/resource2/?p1=1&p2=2', 200)
('/resource2/?p1=1&p2=2', 200),
('/resource2/a/b%2Fc', 200),
('/resource2/a/b%2Fc/', 200)
])
async def test_add_trailing_when_necessary(
self, path, status, cli):
Expand All @@ -120,7 +124,9 @@ async def test_add_trailing_when_necessary(
('/resource1?p1=1&p2=2', 200),
('/resource1/?p1=1&p2=2', 404),
('/resource2?p1=1&p2=2', 404),
('/resource2/?p1=1&p2=2', 200)
('/resource2/?p1=1&p2=2', 200),
('/resource2/a/b%2Fc', 404),
('/resource2/a/b%2Fc/', 200)
])
async def test_no_trailing_slash_when_disabled(
self, path, status, cli):
Expand Down