From 735fffbd9840937fec758c907a60930aba19419f Mon Sep 17 00:00:00 2001 From: linw1995 Date: Wed, 19 Sep 2018 19:02:43 +0800 Subject: [PATCH 1/5] `TestNormalizePathMiddleware` should check the query string --- tests/test_web_middleware.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_web_middleware.py b/tests/test_web_middleware.py index e107cc17b1b..405bf57e22c 100644 --- a/tests/test_web_middleware.py +++ b/tests/test_web_middleware.py @@ -3,6 +3,7 @@ import pytest from aiohttp import web +from yarl import URL async def test_middleware_modifies_response(loop, aiohttp_client): @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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): From 6c899b020a49dbb1084cfe42e57ba7c5e6be3f61 Mon Sep 17 00:00:00 2001 From: linw1995 Date: Wed, 19 Sep 2018 19:03:22 +0800 Subject: [PATCH 2/5] `normalize_path_middleware` should keep the query string --- aiohttp/web_middlewares.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/web_middlewares.py b/aiohttp/web_middlewares.py index f762f5b8bf5..4e339acab85 100644 --- a/aiohttp/web_middlewares.py +++ b/aiohttp/web_middlewares.py @@ -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) From e815f19abb3eb83587cde0770fdd3e4039426c1e Mon Sep 17 00:00:00 2001 From: linw1995 Date: Wed, 19 Sep 2018 21:49:13 +0800 Subject: [PATCH 3/5] sort the import --- tests/test_web_middleware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_web_middleware.py b/tests/test_web_middleware.py index 405bf57e22c..3fac4755ffc 100644 --- a/tests/test_web_middleware.py +++ b/tests/test_web_middleware.py @@ -1,9 +1,9 @@ import re import pytest +from yarl import URL from aiohttp import web -from yarl import URL async def test_middleware_modifies_response(loop, aiohttp_client): From 77028126e1f6f67b7a470d54efdcd14356b6274f Mon Sep 17 00:00:00 2001 From: linw1995 Date: Wed, 19 Sep 2018 21:51:19 +0800 Subject: [PATCH 4/5] add CHANGES/3278.bugfix --- CHANGES/3278.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/3278.bugfix diff --git a/CHANGES/3278.bugfix b/CHANGES/3278.bugfix new file mode 100644 index 00000000000..5908fecba09 --- /dev/null +++ b/CHANGES/3278.bugfix @@ -0,0 +1 @@ +`normalize_path_middleware` should keep the query string. From 204fe72feef6206a95f4724aba081f5121edf23a Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 19 Sep 2018 21:14:15 +0300 Subject: [PATCH 5/5] Update 3278.bugfix --- CHANGES/3278.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/3278.bugfix b/CHANGES/3278.bugfix index 5908fecba09..bbc6b53b9cc 100644 --- a/CHANGES/3278.bugfix +++ b/CHANGES/3278.bugfix @@ -1 +1 @@ -`normalize_path_middleware` should keep the query string. +Keep the query string by `normalize_path_middleware`.