Ver código fonte

[Routing] fixed UrlMatcher when no method requirement is defined

Fabien Potencier 14 anos atrás
pai
commit
e159c47cc9

+ 1 - 1
src/Symfony/Component/Routing/Matcher/UrlMatcher.php

@@ -78,7 +78,7 @@ class UrlMatcher implements UrlMatcherInterface
             }
 
             // check HTTP method requirement
-            if (isset($this->context['method']) && ($req = explode('|', $route->getRequirement('_method'))) && !in_array(strtolower($this->context['method']), array_map('strtolower', $req))) {
+            if (isset($this->context['method']) && $route->getRequirement('_method') && ($req = explode('|', $route->getRequirement('_method'))) && !in_array(strtolower($this->context['method']), array_map('strtolower', $req))) {
                 $allow = array_merge($allow, $req);
                 continue;
             }

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

@@ -19,6 +19,15 @@ use Symfony\Component\Routing\RouteCollection;
 
 class UrlMatcherTest extends \PHPUnit_Framework_TestCase
 {
+    public function testNoMethodSoAllowed()
+    {
+        $coll = new RouteCollection();
+        $coll->add('foo', new Route('/foo'));
+
+        $matcher = new UrlMatcher($coll, array('method' => 'get'));
+        $matcher->match('/foo');
+    }
+
     public function testMethodNotAllowed()
     {
         $coll = new RouteCollection();