فهرست منبع

[HttpFoundation] changed RequestMatcher pattern syntax

Fabien Potencier 14 سال پیش
والد
کامیت
fafcd02684

+ 3 - 3
src/Symfony/Component/HttpFoundation/RequestMatcher.php

@@ -85,16 +85,16 @@ class RequestMatcher implements RequestMatcherInterface
         }
 
         foreach ($this->attributes as $key => $pattern) {
-            if (!preg_match($pattern, $request->attributes->get($key))) {
+            if (!preg_match('#^'.$pattern.'$#', $request->attributes->get($key))) {
                 return false;
             }
         }
 
-        if (null !== $this->path && !preg_match($this->path, $request->getPathInfo())) {
+        if (null !== $this->path && !preg_match('#^'.$this->path.'$#', $request->getPathInfo())) {
             return false;
         }
 
-        if (null !== $this->host && !preg_match($this->host, $request->getHost())) {
+        if (null !== $this->host && !preg_match('#^'.$this->host.'$#', $request->getHost())) {
             return false;
         }
 

+ 4 - 4
tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php

@@ -50,11 +50,11 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
     {
         $matcher = new RequestMatcher();
 
-        $matcher->matchHost('#.*\.example\.com#i');
+        $matcher->matchHost('.*\.example\.com');
         $request = Request::create('', 'get', array(), array(), array(), array('HTTP_HOST' => 'foo.example.com'));
         $this->assertTrue($matcher->matches($request));
 
-        $matcher->matchMethod('#sensio\.com#i');
+        $matcher->matchMethod('.*\.sensio\.com');
         $this->assertFalse($matcher->matches($request));
     }
 
@@ -62,11 +62,11 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
     {
         $matcher = new RequestMatcher();
 
-        $matcher->matchPath('#^/admin#');
+        $matcher->matchPath('/admin/.*');
         $request = Request::create('/admin/foo');
         $this->assertTrue($matcher->matches($request));
 
-        $matcher->matchMethod('#^/blog#i');
+        $matcher->matchMethod('/blog/.*');
         $this->assertFalse($matcher->matches($request));
     }
 }