Fix issue with RequestMatcher when attribute is a closure

This commit is contained in:
Morel Sébastien 2021-04-13 12:53:23 -07:00
parent 3f42c08abd
commit 66491238e3
No known key found for this signature in database
GPG Key ID: FFF7C4EB6FEDB154
2 changed files with 18 additions and 1 deletions

View File

@ -167,7 +167,11 @@ class RequestMatcher implements RequestMatcherInterface
} }
foreach ($this->attributes as $key => $pattern) { foreach ($this->attributes as $key => $pattern) {
if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) { $requestAttribute = $request->attributes->get($key);
if (!\is_string($requestAttribute)) {
return false;
}
if (!preg_match('{'.$pattern.'}', $requestAttribute)) {
return false; return false;
} }
} }

View File

@ -163,4 +163,17 @@ class RequestMatcherTest extends TestCase
$matcher->matchAttribute('foo', 'babar'); $matcher->matchAttribute('foo', 'babar');
$this->assertFalse($matcher->matches($request)); $this->assertFalse($matcher->matches($request));
} }
public function testAttributesWithClosure()
{
$matcher = new RequestMatcher();
$request = Request::create('/admin/foo');
$request->attributes->set('_controller', function () {
return new Response('foo');
});
$matcher->matchAttribute('_controller', 'babar');
$this->assertFalse($matcher->matches($request));
}
} }