Fix issue with RequestMatcher when attribute is a closure
This commit is contained in:
parent
3f42c08abd
commit
66491238e3
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user