Переглянути джерело

[Routing] Fix PhpMatcherDump when url contains a . or a -

Benjamin Lévêque 14 роки тому
батько
коміт
8a472b7d98

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

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

+ 4 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php

@@ -33,6 +33,10 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
             return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz'));
         }
 
+        if ($url === '/test/baz.html') {
+            return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz2'));
+        }
+
         return false;
     }
 }

+ 3 - 0
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php

@@ -41,6 +41,9 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
         $collection->add('baz', new Route(
             '/test/baz'
         ));
+        $collection->add('baz2', new Route(
+            '/test/baz.html'
+        ));
 
         $dumper = new PhpMatcherDumper($collection);
         $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');