encode and decode parameters in routes
All checks were successful
soko-web/pipeline/head This commit looks good

This commit is contained in:
Bence Pőcze 2024-11-08 12:21:54 +01:00
parent 5534f10cee
commit d504f1d5bb
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -34,7 +34,7 @@ class Route implements IRoute
foreach ($this->pattern as $fragment) {
if (preg_match('/^{(\\w+)(\\?)?}$/', $fragment, $matches) === 1) {
if (isset($parameters[$matches[1]])) {
$link[] = $parameters[$matches[1]];
$link[] = rawurlencode($parameters[$matches[1]]);
unset($parameters[$matches[1]]);
} elseif (!isset($matches[2])) {//TODO: why? parameter not found but not optional
$link[] = $fragment;
@ -64,7 +64,7 @@ class Route implements IRoute
foreach ($path as $i => $fragment) {
if (preg_match('/^{(\\w+)(?:\\?)?}$/', $this->pattern[$i], $matches) === 1) {
$parameters[$matches[1]] = $fragment;
$parameters[$matches[1]] = rawurldecode($fragment);
} elseif ($fragment != $this->pattern[$i]) {
return null;
}