Skip to content

Commit 5b0782d

Browse files
committed
Route::param2path() allows all characters defined by RFC 3986 [Closes #14]
1 parent 9ebb82a commit 5b0782d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Routing/Route.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ private static function renameKeys(array $arr, array $xlat): array
628628
*/
629629
public static function param2path(string $s): string
630630
{
631-
return str_replace('%2F', '/', rawurlencode($s));
631+
// segment + "/", see https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
632+
return preg_replace_callback(
633+
'#[^\w.~!$&\'()*+,;=:@"/-]#',
634+
fn($m) => rawurlencode($m[0]),
635+
$s,
636+
);
632637
}
633638
}

tests/Route/urlEncoding.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $route = new Route('<param .*>');
1717
testRouteIn($route, '/a%3A%25%2Fb', [
1818
'param' => 'a:%/b',
1919
'test' => 'testvalue',
20-
], '/a%3A%25/b?test=testvalue');
20+
], '/a:%25/b?test=testvalue');
2121

2222

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

0 commit comments

Comments
 (0)