[HttpFoundation] changed RequestMatcher pattern syntax

This commit is contained in:
Fabien Potencier 2010-10-07 19:12:53 +02:00
parent 18caddec7a
commit fafcd02684
2 changed files with 7 additions and 7 deletions

View File

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

View File

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