Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Missing redirection when route param does not accept trailing slash #30863

Copy link
Copy link
Closed
@marc-romera

Description

@marc-romera
Issue body actions

Symfony version(s) affected: 4.2.4

Description
Symfony 4 does not redirect in a route ending with a param which does not accept a trailing slash. Route can disallow a trailing slash if configured as shown here. Symfony 4 should detect that the route is invalid with a trailing slash (but valid without it) and so return a redirect response to the same route without the slash.

How to reproduce
Step 1. Set your route

#app/config/routing.yml
index:
    path:       /check/{token}
    controller:  AppBundle:Default:token
    defaults:
        token: 1
    requirements:
        token: \d+

Step 2. Implement the action

// src/AppBundle/Controller/DefaultController.php
class DefaultController extends Controller
{
    /**
     * @param $token
     *
     * @return Response
     */
    public function tokenAction(string $token)
    {
        return new Response('token is ' . $token);
    }
}

Step 3. Serve the application and visit the path http://127.0.0.1:8000/check/123/
The output is the one it would provide without the slash:
token is 123

But we want it to actually be redirected to http://127.0.0.1:8000/check/123, which is the only valid one, already working and returning the same exact response.

Additional context
Route-related log is identical in both cases (i.e., with and without the trailing slash):
[2019-04-04 09:50:35] request.INFO: Matched route "test". {"route":"test","route_parameters":{"_route":"test","token":"123","_controller":"AppBundle\\Controller\\DefaultController::tokenAction"},"request_uri":"http://127.0.0.1:8000/check/123/","method":"GET"} []

PS: Example heavily based on #29924, which seems somewhat related to this issue

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.