diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 9a4a2a13761e1..82be2d8681b2b 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/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/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php index 57e9c3d30f2c9..e913a60c84201 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php +++ b/src/Symfony/Component/HttpFoundation/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)); + } }