You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be an unexpected behavior when mixing paths with trailing slashes and a route with a path/regex parameter. When creating an app with strict_slashes=False, one would expect that static routes will match paths with and without the trailing slash as a top priority. But paths with a trailing slash are actually a "last resource" when looking for a matching route.
Because strict_slashes=False, the hello_world route is supposed to match both /hello and /hello/. But the latter is being matched with the catch_all route.
I am not sure that is likely to change anytime soon. That would be a pretty big change to do it differently. And, part of the reason it is implemented as such is for performance. I'll have to think on this some more, and I'm happy to hear suggestions, but I do not know of a good way to handle this currently without making some sacrifices.
Problem
There seems to be an unexpected behavior when mixing paths with trailing slashes and a route with a path/regex parameter. When creating an app with
strict_slashes=False
, one would expect that static routes will match paths with and without the trailing slash as a top priority. But paths with a trailing slash are actually a "last resource" when looking for a matching route.Code snippet
Expected behavior
Because
strict_slashes=False
, thehello_world
route is supposed to match both/hello
and/hello/
. But the latter is being matched with thecatch_all
route.Looks like this is happening due to how the
resolve
method works rigt now: https://github.com/sanic-org/sanic-routing/blob/main/sanic_routing/router.py#L92; it's looking for the route with the trailing slash only when no other route would match.Sanic version
The text was updated successfully, but these errors were encountered: