8000 Fix issue with RequestMatcher when attribute is a closure · symfony/symfony@6649123 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6649123

Browse files
committed
Fix issue with RequestMatcher when attribute is a closure
1 parent 3f42c08 commit 6649123

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ public function matches(Request $request)
167167
}
168168

169169
foreach ($this->attributes as $key => $pattern) {
170-
if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
170+
$requestAttribute = $request->attributes->get($key);
171+
if (!\is_string($requestAttribute)) {
172+
return false;
173+
}
174+
if (!preg_match('{'.$pattern.'}', $requestAttribute)) {
171175
return false;
172176
}
173177
}

src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,17 @@ public function testAttributes()
163163
$matcher->matchAttribute('foo', 'babar');
164164
$this->assertFalse($matcher->matches($request));
165165
}
166+
167+
public function testAttributesWithClosure()
168+
{
169+
$matcher = new RequestMatcher();
170+
171+
$request = Request::create('/admin/foo');
172+
$request->attributes->set('_controller', function () {
173+
return new Response('foo');
174+
});
175+
176+
$matcher->matchAttribute('_controller', 'babar');
177+
$this->assertFalse($matcher->matches($request));
178+
}
166179
}

0 commit comments

Comments
 (0)
0