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
Colon in uri generate response 404 #2553
Comments
Please open this in https://github.com/sanic-org/sanic-routing as well |
@sjsadowski no need to do that, we can just move it between projects |
For reference, this is not a path defined character, and is explicitly reserved in the spec. I'm not sure rhat it is something in need of changing, and I certainly would not call this a bug. |
That if is a problem. Have you tried it from a browser (not encoded)? Browsers or webhook will not do that. If a route is, |
fwiw same happens with other characters such as |
I guess the question then is what non-spec-compliant characters (if any) should we support? |
I am going to put this aside for now unless someone can make a compelling argument for why we need to handle this. It is the first time I have heard this come up and I am hesitant to add in support for this edge case when a viable alternative exists. For anyone that needs: from urllib.parse import quote
from sanic import Request, Sanic, json
from sanic.router import Router
class MyRouter(Router):
def get(self, path, *args, **kwargs):
return super().get(quote(path), *args, **kwargs)
app = Sanic("TestApp", router=MyRouter())
@app.route("/x:y")
async def handler(request: Request):
return json({"foo": "bar"}) Or, perhaps a try/except is warranted: def get(self, path, *args, **kwargs):
try:
return super().get(path, *args, **kwargs)
except NotFound:
return super().get(quote(path), *args, **kwargs) |
Closing as WONTFIX, given that it against specs and as @ahopkins noted a rare corner case with viable workarounds for those who need it anyway. |
Sanic can't find the route if there's a colon in the uri.
Code snippet
Expected behavior
GET http://127.0.0.1:8000/abc/x:y 200 0
Actual behavior
GET http://127.0.0.1:8000/abc/x:y 404 733
Environment
Additional context
tiangolo/fastapi#4892
encode/starlette#1657
The text was updated successfully, but these errors were encountered: