diff --git a/src/Routing/Route.php b/src/Routing/Route.php
index c292a5e..a36f2dc 100644
--- a/src/Routing/Route.php
+++ b/src/Routing/Route.php
@@ -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,
+ );
}
}
diff --git a/tests/Route/urlEncoding.phpt b/tests/Route/urlEncoding.phpt
index 303a1f0..63b4960 100644
--- a/tests/Route/urlEncoding.phpt
+++ b/tests/Route/urlEncoding.phpt
@@ -17,7 +17,7 @@ $route = new Route('');
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('', [