From ff1f027bdadf55889df251607df054bf30dcda38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 24 Nov 2016 10:04:47 +0100 Subject: [PATCH] Make sure parameter-modifier is found before parsing parameters. --- src/Pecee/SimpleRouter/Route/LoadableRoute.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Pecee/SimpleRouter/Route/LoadableRoute.php b/src/Pecee/SimpleRouter/Route/LoadableRoute.php index 3971cf9..c51eb19 100644 --- a/src/Pecee/SimpleRouter/Route/LoadableRoute.php +++ b/src/Pecee/SimpleRouter/Route/LoadableRoute.php @@ -48,14 +48,19 @@ abstract class LoadableRoute extends Route implements ILoadableRoute public function setUrl($url) { $this->url = ($url === '/') ? '/' : '/' . trim($url, '/') . '/'; - $regex = sprintf(static::PARAMETERS_REGEX_MATCH, $this->paramModifiers[0], $this->paramOptionalSymbol, $this->paramModifiers[1]); - if (preg_match_all('/' . $regex . '/is', $this->url, $matches)) { + if(strpos($this->url, $this->paramModifiers[0]) !== false) { - $max = count($matches[1]); + $regex = sprintf(static::PARAMETERS_REGEX_MATCH, $this->paramModifiers[0], $this->paramOptionalSymbol, $this->paramModifiers[1]); + + if (preg_match_all('/' . $regex . '/is', $this->url, $matches)) { + + $max = count($matches[1]); + + for ($i = 0; $i < $max; $i++) { + $this->parameters[$matches[1][$i]] = null; + } - for($i = 0; $i < $max; $i++) { - $this->parameters[$matches[1][$i]] = null; } }