Skip to content

Commit

Permalink
Fix resource reuse with regex paths (#8998)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Sep 4, 2024
1 parent 495f1a2 commit 875f23d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/8998.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an error when trying to add a route for multiple methods with a path containing a regex pattern -- by :user:`Dreamsorcerer`.
3 changes: 2 additions & 1 deletion aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class DynamicResource(Resource):

def __init__(self, path: str, *, name: Optional[str] = None) -> None:
super().__init__(name=name)
self._orig_path = path
pattern = ""
formatter = ""
for part in ROUTE_RE.split(path):
Expand Down Expand Up @@ -484,7 +485,7 @@ def _match(self, path: str) -> Optional[Dict[str, str]]:
}

def raw_match(self, path: str) -> bool:
return self._formatter == path
return self._orig_path == path

def get_info(self) -> _InfoDict:
return {"formatter": self._formatter, "pattern": self._pattern}
Expand Down
5 changes: 3 additions & 2 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,11 @@ async def handler(request: web.Request) -> web.Response:

@pytest.mark.parametrize(
"path",
[
(
"/a",
"/{a}",
],
"/{a:.*}",
),
)
def test_reuse_last_added_resource(path: str) -> None:
# Test that adding a route with the same name and path of the last added
Expand Down

0 comments on commit 875f23d

Please sign in to comment.