1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-03 23:17:38 +02:00

prevent strip of preceding slash at base

This commit is contained in:
Koen Punt
2014-12-22 13:05:02 +01:00
parent f18a57d481
commit be64536dcb

View File

@@ -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;