From e5da9f246451f65b86334b67fde39bd79d7ca384 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 17:33:38 +0000 Subject: [PATCH] [PR #5635/09ac1cbb backport][3.8] Add regression test for #5621 (#5636) Co-authored-by: Sviatoslav Sydorenko Co-authored-by: Alexander Mohr --- CHANGES/5635.misc | 1 + tests/test_web_urldispatcher.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 CHANGES/5635.misc diff --git a/CHANGES/5635.misc b/CHANGES/5635.misc new file mode 100644 index 00000000000..c4ec37f8d26 --- /dev/null +++ b/CHANGES/5635.misc @@ -0,0 +1 @@ +Added regression tests for dispatching urlencoded routes. diff --git a/tests/test_web_urldispatcher.py b/tests/test_web_urldispatcher.py index 0ba2e7c2034..354be354496 100644 --- a/tests/test_web_urldispatcher.py +++ b/tests/test_web_urldispatcher.py @@ -9,6 +9,7 @@ from unittest.mock import MagicMock import pytest +import yarl from aiohttp import abc, web from aiohttp.web_urldispatcher import SystemRoute @@ -515,3 +516,35 @@ async def test_static_absolute_url(aiohttp_client, tmpdir) -> None: client = await aiohttp_client(app) resp = await client.get("/static/" + str(fname)) assert resp.status == 403 + + +@pytest.mark.xfail( + raises=AssertionError, + reason="Regression in v3.7: https://github.com/aio-libs/aiohttp/issues/5621", +) +@pytest.mark.parametrize( + ("route_definition", "urlencoded_path", "expected_http_resp_status"), + ( + ("/467,802,24834/hello", "/467%2C802%2C24834/hello", 200), + ("/{user_ids:([0-9]+)(,([0-9]+))*}/hello", "/467%2C802%2C24834/hello", 200), + ("/1%2C3/hello", "/1%2C3/hello", 404), + ), + ids=("urldecoded_route", "urldecoded_route_with_regex", "urlencoded_route"), +) +async def test_decoded_url_match( + aiohttp_client, + route_definition, + urlencoded_path, + expected_http_resp_status, +) -> None: + app = web.Application() + + async def handler(_): + return web.Response() + + app.router.add_get(route_definition, handler) + client = await aiohttp_client(app) + + r = await client.get(yarl.URL(urlencoded_path, encoded=True)) + assert r.status == expected_http_resp_status + await r.release()