Skip to content

Commit

Permalink
Fix issue with RequestMatcher when attribute is a closure
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Apr 15, 2021
1 parent 005b951 commit bc4e440
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion RequestMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/RequestMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit bc4e440

Please sign in to comment.