Routing does not match (slash %2F in path parameter)
When you have the following route:
$router->any('/something/{magic}/{foo}', function (ServerRequestInterface $request, Response $response, array $args) use ($app) {
// do something
});
And Call this URL:
https://some.host/something/magic/foo%2Fbar
It will not match. I tried to check what went wrong. In $_SERVER I get:
["REQUEST_URI"]=>
string(32) "/something/magic/foo%2Fbar"
It however matches when commenting out: https://github.com/slimphp/Slim/blob/4.x/Slim/Routing/RouteResolver.php#L42
Not sure why this is there tbh? If you want the route parameter to be decoded, shouldn't this be done after routing is done?
It seems the rawurldecode($uri) was originally added to solve another issue for routes with international characters before Slim 4:
See commit https://github.com/slimphp/Slim/pull/2405/commits/9c50cb9e1291fbff05ce63a08de262a891035a04 in PR #2405 for issue #2399
For the specific case of %2F here that is indeed not expected if you compare with the comment $uri Should be $request->getUri()->getPath(). In fact PSR-7 gives that explicit example for getPath() when talking about percent-encoded values.
But I guess it's been around for so long now (2018) that this is a "known quirk" for Slim 4 routing? Work-around could be to double-encode %2F into %252F first...
I think is an "historical" artifact from v3 or v4, see here: https://github.com/slimphp/Slim/issues/3208#issuecomment-1203427234
We have to do a rawurldecode() before dispatching the URI to the router otherwise it would break when encountering special chars.
We will address this in v5.