Skip to content

Commit

Permalink
normalize_path_middleware should keep the query string. (#3278)
Browse files Browse the repository at this point in the history
* `TestNormalizePathMiddleware` should check the query string

* `normalize_path_middleware` should keep the query string

* sort the import

* add CHANGES/3278.bugfix

* Update 3278.bugfix
  • Loading branch information
林玮 authored and asvetlov committed Sep 20, 2018
1 parent 6b112b0 commit 6cb85a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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

0 comments on commit 6cb85a7

Please sign in to comment.