Skip to content

Commit

Permalink
[HttpFoundation] changed RequestMatcher pattern syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 7, 2010
1 parent 18cadde commit fafcd02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/HttpFoundation/RequestMatcher.php
Expand Up @@ -85,16 +85,16 @@ public function matches(Request $request)
}

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;
}

Expand Down
Expand Up @@ -50,23 +50,23 @@ public function testHost()
{
$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));
}

public function testPath()
{
$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));
}
}

0 comments on commit fafcd02

Please sign in to comment.