-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
router.add_static is greedy #5250
Comments
The order of routes is important, the search is stopped on the first match. |
@asvetlov I'm not sure what you mean by "more ready". |
|
@alex-eri That has no effect due to this logic where any trailing slash is removed: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_urldispatcher.py#L1097 |
I also encountered this. It's rather surprising that It seems like the fix should be in async def resolve(self, request: Request) -> _Resolve:
path = request.rel_url.raw_path
method = request.method
allowed_methods = set(self._routes)
if not path.startswith(self._prefix + "/"):
return None, set()
# .... That seems safe and correct considering that the resolved filename implicitly assumes that the character following the prefix is irrelevant:
|
I think this fixes aio-libs#5250
🐞 Describe the bug
The first argument for
add_static
matches on any path that starts with that string. For instance, if you specify "h", thenadd_static
will match on "h" or "help" or "hoover".💡 To Reproduce
Run this code:
Add a text file in the current working directory named
test.txt
and put some text in there.Then navigate to the following URLs to demonstrate the issue:
The last link unexpectedly returns a 404.
💡 Expected behavior
I would have expected http://0.0.0.0:8080/hoover to have similar behavior to http://0.0.0.0:8080/groot, and render "Hello, hoover".
📋 Your version of the Python
3.8
📋 Your version of the aiohttp/yarl/multidict distributions
aiohttp 3.7.2
The text was updated successfully, but these errors were encountered: