Skip to content

Commit

Permalink
Do not use translated path (#3051)
Browse files Browse the repository at this point in the history
* Do not use translated path

Redirect would fail in case we have encoded url, e.g.
/foo/bar%2Fbar -> /foo/bar/bar/

* Use request.raw_path as mandated by @asvetlov
  • Loading branch information
william-gr authored and asvetlov committed Jun 9, 2018
1 parent d8831f3 commit 4b54daf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
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)
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

0 comments on commit 4b54daf

Please sign in to comment.