Skip to content

[Routing] Inconsistent Routes Matching When Slash Match Requested #27385

@kiler129

Description

@kiler129

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:
image

How to reproduce

  1. Create singular routes.yaml file in /config/
  2. Put the routing specified above there
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions