Skip to content

Commit

Permalink
Route::param2path() allows all characters defined by RFC 3986 [Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 4, 2024
1 parent 9ebb82a commit 5b0782d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ private static function renameKeys(array $arr, array $xlat): array
*/
public static function param2path(string $s): string
{
return str_replace('%2F', '/', rawurlencode($s));
// segment + "/", see https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
return preg_replace_callback(
'#[^\w.~!$&\'()*+,;=:@"/-]#',
fn($m) => rawurlencode($m[0]),
$s,
);
}
}
2 changes: 1 addition & 1 deletion tests/Route/urlEncoding.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $route = new Route('<param .*>');
testRouteIn($route, '/a%3A%25%2Fb', [
'param' => 'a:%/b',
'test' => 'testvalue',
], '/a%3A%25/b?test=testvalue');
], '/a:%25/b?test=testvalue');


$route = new Route('<param .*>', [
Expand Down

0 comments on commit 5b0782d

Please sign in to comment.