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
"ValueError: Invalid declaration" with routes containing file extensions #2206
Comments
Actually, starting in 21.3. The issue is not the |
Can you clarify what is meant by "partial matches"? |
@jacebrowning Sorry for being super brief yesterday. Take a look at this: https://sanicframework.org/en/guide/basics/routing.html#regex-matching By "partial", I meant trying to capture only some of a single path segment, and not the entirety. Beginning in 21.3 the The most obvious and common need is exactly as you are running into it (matching on a file extension). This is why I proposed: sanic-org/sanic-routing#27. I hope this clears it up. You should be able to do this: @app.get(r"/<name:.+\.txt>")
def example(request, name):
return response.text(f"Hello, {name}!") |
@ahopkins Thanks for the clarification! Using patterns like I'm definitely a fan of your proposed change to
|
I am hoping to get it in for next release if possible. There definitely are some challenges to allow for extracting multiple variables per segment. Not necessarily in the actual destructuring and matching, but creating a simple abstraction layer for defining the path parameter definitions without creating too much complexity or coupling. |
See: sanic-org/sanic-routing#47 New path parameter type: @app.get(r"/<name:ext:txt>")
def example(request, name, ext):
return response.text(f"Hello, {name}!") |
@ahopkins Why is this not allowed? I would expect the obvious and simple thing to work, i.e. the route |
@khogeland could you open a new issue or bring the discussion to the forums or discord? Thanks. |
Describe the bug
Starting in Sanic 21.6.1, routes with periods in them (e.g.
"/<name>.txt"
) are no longer accepted:Code snippet
Expected behavior
With
sanic==21.6.0
andsanic-routing==0.7.0
, the app is able to start but/foobar.txt
is not routed:With
sanic==20.12.3
, the app both starts and correctly routes/foobar.txt
to the function:Environment
sanic==21.6.1
andsanic-routing==0.7.1
The text was updated successfully, but these errors were encountered: