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

normalize_path_middleware should keep the query string. #3278

Merged
merged 5 commits into from
Sep 20, 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/3278.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep the query string by `normalize_path_middleware`.
2 changes: 1 addition & 1 deletion aiohttp/web_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def impl(request, handler):
resolves, request = await _check_request_resolves(
request, path)
if resolves:
raise redirect_class(request.raw_path)
raise redirect_class(request.raw_path + query)

return await handler(request)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_web_middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

import pytest
from yarl import URL

from aiohttp import web

Expand Down Expand Up @@ -115,6 +116,7 @@ async def test_add_trailing_when_necessary(

resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

@pytest.mark.parametrize("path, status", [
('/resource1', 200),
Expand All @@ -136,6 +138,7 @@ async def test_remove_trailing_when_necessary(self, path, status, cli):

resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

@pytest.mark.parametrize("path, status", [
('/resource1', 200),
Expand All @@ -158,6 +161,7 @@ async def test_no_trailing_slash_when_disabled(

resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

@pytest.mark.parametrize("path, status", [
('/resource1/a/b', 200),
Expand All @@ -180,6 +184,7 @@ async def test_merge_slash(self, path, status, cli):

resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

@pytest.mark.parametrize("path, status", [
('/resource1/a/b', 200),
Expand Down Expand Up @@ -220,6 +225,7 @@ async def test_append_and_merge_slash(self, path, status, cli):
client = await cli(extra_middlewares)
resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

@pytest.mark.parametrize("path, status", [
('/resource1/a/b', 200),
Expand Down Expand Up @@ -262,6 +268,7 @@ async def test_remove_and_merge_slash(self, path, status, cli):
client = await cli(extra_middlewares)
resp = await client.get(path)
assert resp.status == status
assert resp.url.query == URL(path).query

async def test_cannot_remove_and_add_slash(self):
with pytest.raises(AssertionError):
Expand Down