Description
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