mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-01-17 12:18:16 +01:00
prevent strip of preceding slash at base
This commit is contained in:
parent
f18a57d481
commit
be64536dcb
@ -139,7 +139,7 @@ class AltoRouter {
|
||||
|
||||
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;
|
||||
|
||||
if ($pre) {
|
||||
@ -147,13 +147,17 @@ class AltoRouter {
|
||||
}
|
||||
|
||||
if(isset($params[$param])) {
|
||||
// Part is found, replace for param value
|
||||
$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);
|
||||
} else {
|
||||
// Strip match block
|
||||
$url = str_replace($block, '', $url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
Loading…
x
Reference in New Issue
Block a user