Skip to content

Commit

Permalink
Do not use translated path
Browse files Browse the repository at this point in the history
Redirect would fail in case we have encoded url, e.g.
/foo/bar%2Fbar -> /foo/bar/bar/
  • Loading branch information
william-gr committed Jun 5, 2018
1 parent 466cb4a commit b6fd755
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(path + query)

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 b6fd755

Please sign in to comment.