Skip to content

[4.2] [Routing] Matching trailing slashes is not possible anymore #29734

@derrabus

Description

@derrabus

Symfony version(s) affected: 4.2.2-dev

Description
We have certain routes that have a suffix that is passed as-is to the controller. If the suffix is just a singe slash, that slash is not matched anymore.

Since we strip the slash anyway, this only broke our integration tests. However, such a change is a bit unexpected between minor versions.

How to reproduce

use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

$routeCollection = new RouteCollection();
$routeCollection->add('test', new Route(
    '/some/route{pathSuffix}',
    ['pathSuffix' => ''],
    ['pathSuffix' => '(|/.*)']
));

$matcher = new UrlMatcher($routeCollection, new RequestContext());

dump($matcher->match('/some/route/'));

Output with Routing 4.2.1 and below:

array:2 [
  "pathSuffix" => "/"
  "_route" => "test"
]

Output with Routing 4.2.2-dev:

array:2 [
  "pathSuffix" => ""
  "_route" => "test"
]

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