mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-02 22:47:31 +02:00
prevent strip of preceding slash at base
This commit is contained in:
@@ -139,7 +139,7 @@ class AltoRouter {
|
|||||||
|
|
||||||
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
|
||||||
|
|
||||||
foreach($matches as $match) {
|
foreach($matches as $index => $match) {
|
||||||
list($block, $pre, $type, $param, $optional) = $match;
|
list($block, $pre, $type, $param, $optional) = $match;
|
||||||
|
|
||||||
if ($pre) {
|
if ($pre) {
|
||||||
@@ -147,13 +147,17 @@ class AltoRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(isset($params[$param])) {
|
if(isset($params[$param])) {
|
||||||
|
// Part is found, replace for param value
|
||||||
$url = str_replace($block, $params[$param], $url);
|
$url = str_replace($block, $params[$param], $url);
|
||||||
} elseif ($optional) {
|
} elseif ($optional && $index !== 0) {
|
||||||
|
// Only strip preceeding slash if it's not at the base
|
||||||
$url = str_replace($pre . $block, '', $url);
|
$url = str_replace($pre . $block, '', $url);
|
||||||
|
} else {
|
||||||
|
// Strip match block
|
||||||
|
$url = str_replace($block, '', $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
Reference in New Issue
Block a user