소스 검색

[Routing] fixed UrlMatcher when no method requirement is defined

Fabien Potencier 14 년 전
부모
커밋
e159c47cc9
2개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/Symfony/Component/Routing/Matcher/UrlMatcher.php
  2. 9 0
      tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php

+ 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();