From f7ea68f70c1f8a00d376f67f3cdd02d35b26a638 Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Sat, 17 Nov 2012 14:39:14 +0000 Subject: [PATCH 1/2] [Routing] Fixed undefined variable + typo --- .../Routing/Matcher/Dumper/ApacheMatcherDumper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php index 73ace8afa6..f39ea3d539 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php @@ -47,16 +47,16 @@ class ApacheMatcherDumper extends MatcherDumper $rules = array("# skip \"real\" requests\nRewriteCond %{REQUEST_FILENAME} -f\nRewriteRule .* - [QSA,L]"); $methodVars = array(); $hostnameRegexUnique = 0; - $prevHosnameRegex = ''; + $prevHostnameRegex = ''; foreach ($this->getRoutes()->all() as $name => $route) { $compiledRoute = $route->compile(); $hostnameRegex = $compiledRoute->getHostnameRegex(); - if (null !== $hostnameRegex && $prevHosnameRegex !== $hostnameRegex) { + if (null !== $hostnameRegex && $prevHostnameRegex !== $hostnameRegex) { - $prevHosnameRegex = $hostnameRegex; + $prevHostnameRegex = $hostnameRegex; $hostnameRegexUnique++; $rule = array(); @@ -217,7 +217,7 @@ class ApacheMatcherDumper extends MatcherDumper $delimiter = $regex[0]; $regexPatternEnd = strrpos($regex, $delimiter); if (strlen($regex) < 2 || 0 === $regexPatternEnd) { - throw new \LogicException('The "%s" route regex "%s" is invalid', $name, $regex); + throw new \LogicException('The route regex "%s" is invalid', $regex); } $regex = preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1)); From 38802ea32ca92f3e3e9db973c43a08d6dc1b7646 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sat, 17 Nov 2012 16:58:52 +0100 Subject: [PATCH 2/2] remove logic that could not be triggered anyway the regex by the compiler is always valid. even if it was invalid like '' it wasn't caught by the exception and would have given a php notice. --- .../Routing/Matcher/Dumper/ApacheMatcherDumper.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php index f39ea3d539..8017a7bc34 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php @@ -214,14 +214,9 @@ class ApacheMatcherDumper extends MatcherDumper */ private function regexToApacheRegex($regex) { - $delimiter = $regex[0]; - $regexPatternEnd = strrpos($regex, $delimiter); - if (strlen($regex) < 2 || 0 === $regexPatternEnd) { - throw new \LogicException('The route regex "%s" is invalid', $regex); - } - $regex = preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1)); + $regexPatternEnd = strrpos($regex, $regex[0]); - return $regex; + return preg_replace('/\?<.+?>/', '', substr($regex, 1, $regexPatternEnd - 1)); } /**