浏览代码

[Routing] made an empty path info to redirect to / (as for any other route that ends with a /)

Fabien Potencier 14 年之前
父节点
当前提交
e16c666266

+ 1 - 1
src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php

@@ -70,7 +70,7 @@ class ApacheMatcherDumper extends MatcherDumper
             $regexes[] = sprintf("%sRewriteCond %%{PATH_INFO} %s\nRewriteRule .* %s [QSA,L,%s]", $conditions, $regex, $options['script_name'], $variables);
 
             // add redirect for missing trailing slash
-            if ('/$' === substr($regex, -2) && '^/$' !== $regex) {
+            if ('/$' === substr($regex, -2)) {
                 $regexes[count($regexes)-1] .= sprintf("\nRewriteCond %%{PATH_INFO} %s\nRewriteRule .* /$0/ [QSA,L,R=301]", substr($regex, 0, -2).'$');
             }
         }

+ 1 - 1
src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

@@ -62,7 +62,7 @@ class PhpMatcherDumper extends MatcherDumper
 
             $hasTrailingSlash = false;
             if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P<url>.*?)\$\1#', $compiledRoute->getRegex(), $m)) {
-                if (substr($m['url'], -1) === '/' && $m['url'] !== '/') {
+                if (substr($m['url'], -1) === '/') {
                     $conditions[] = sprintf("rtrim(\$url, '/') === '%s'", rtrim(str_replace('\\', '', $m['url']), '/'));
                     $hasTrailingSlash = true;
                 } else {

+ 0 - 5
src/Symfony/Component/Routing/Matcher/UrlMatcher.php

@@ -101,11 +101,6 @@ class UrlMatcher implements UrlMatcherInterface
 
     protected function normalizeUrl($url)
     {
-        // ensure that the URL starts with a /
-        if ('/' !== substr($url, 0, 1)) {
-            throw new \InvalidArgumentException(sprintf('URL "%s" is not valid (it does not start with a /).', $url));
-        }
-
         // remove the query string
         if (false !== $pos = strpos($url, '?')) {
             $url = substr($url, 0, $pos);

+ 0 - 9
tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php

@@ -28,15 +28,6 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('/foo/bar', $matcher->normalizeUrl('/foo//bar'), '->normalizeUrl() removes duplicated /');
     }
 
-    /**
-     * @expectedException \InvalidArgumentException
-     */
-    public function testNormalizeUrlThrowsAnExceptionIfTheUrlIsInvalid()
-    {
-        $matcher = new UrlMatcherForTests(new RouteCollection(), array(), array());
-        $matcher->normalizeUrl('');
-    }
-
     public function testMatch()
     {
       // test the patterns are matched are parameters are returned