This repository was archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Slashes in route params are unescaped when passing uri option #56
Copy link
Copy link
Open
Description
- I was not able to find an open or closed issue matching what I'm seeing.
- This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
I expect a parameter passed to a segment route to always be escaped. When I pass an uri option when assembling a route, for whatever reason slashes in the route parameters are unescaped. This causes the route to no longer match correctly.
$router = \Zend\Router\Http\TreeRouteStack::factory([
'routes' => [
'example-route' => [
'type' => \Zend\Router\Http\Segment::class,
'options' => [
'route' => '/example/route/with/:token',
],
],
],
]);
var_dump($router->assemble([
'token' => 'token/with/slashes',
], [
'name' => 'example-route',
]));
// string(42) "/example/route/with/token%2Fwith%2Fslashes"
var_dump($router->assemble([
'token' => 'token/with/slashes',
], [
'name' => 'example-route',
'uri' => new \Zend\Uri\Uri('/'),
]));
// string(38) "/example/route/with/token/with/slashes"I expect the token parameter in the second case to also become encoded. For some reason passing an uri without normalize_path: false normalizes the path, unescaping the passed parameters.
Undesired normalization happens by default in these places:
zend-router/src/Http/TreeRouteStack.php
Lines 420 to 422 in 5ce5ff9
| if (! isset($options['normalize_path']) || $options['normalize_path']) { | |
| $uri->normalize(); | |
| } |
zend-router/src/Http/TreeRouteStack.php
Lines 428 to 430 in 5ce5ff9
| if (! isset($options['normalize_path']) || $options['normalize_path']) { | |
| $uri->normalize(); | |
| } |
Metadata
Metadata
Assignees
Labels
No labels