diff --git a/RequestMatcher.php b/RequestMatcher.php index 9a4a2a137..82be2d868 100644 --- a/RequestMatcher.php +++ b/RequestMatcher.php @@ -167,7 +167,11 @@ public function matches(Request $request) } 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; } } diff --git a/Tests/RequestMatcherTest.php b/Tests/RequestMatcherTest.php index 57e9c3d30..e913a60c8 100644 --- a/Tests/RequestMatcherTest.php +++ b/Tests/RequestMatcherTest.php @@ -163,4 +163,17 @@ public function testAttributes() $matcher->matchAttribute('foo', 'babar'); $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)); + } }