-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 4.1
Description
When following routes configuration is defined:
pages:
path: /{id}.html
defaults: { _controller: App\Controller\DefaultController:test }
requirements:
id: ".+"
catch_all:
path: /{all}
defaults: { _controller: App\Controller\DefaultController:test }
requirements:
all: ".+"
Matching routes is inconsistent between web profiler, request and console. To make this simple look at the table below:
URI | Request | router:match | Profiler | Expected |
---|---|---|---|---|
/test.html |
catch_all |
pages |
pages |
pages |
/foo/test.html |
catch_all |
pages |
pages |
pages |
/foo/bar |
catch_all |
catch_all |
catch_all |
catch_all |
Profiler also disagrees with itself, which would make sense according to the note on the bottom. However no configuration changes are made between request and profiler page view:
How to reproduce
- Create singular
routes.yaml
file in/config/
- Put the routing specified above there
- Visit pages mentioned in table
Possible Solution
I looked at https://symfony.com/doc/current/routing/slash_in_parameter.html and the note describing {_format}
got me:
(...) you shouldn't use the .+ requirement for the parameters that allow slashes. (...) the format will be empty. This can be solved replacing the .+ requirement by [^.]+ to allow any character except dots.
Indeed - changing requirements
to use [^.]+
instead of .+
makes request match as expected, however the inconsistency between results reported in multiple places is worrying.
I don't have experience with routing component internals, but my wild guess would be it may be related to https://symfony.com/blog/new-in-symfony-4-1-fastest-php-router (ping @nicolas-grekas).