Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  Fix DBAL 4 compatibility
  Do not match request twice in HttpUtils
  • Loading branch information
nicolas-grekas committed Oct 13, 2023
2 parents 3c96a51 + a86dc99 commit 573ef96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function createRequest(Request $request, string $path): Request
public function checkRequestPath(Request $request, string $path): bool
{
if ('/' !== $path[0]) {
// Shortcut if request has already been matched before
if ($request->attributes->has('_route')) {
return $path === $request->attributes->get('_route');
}

try {
// matching a request is more powerful than matching a URL path + context, so try that first
if ($this->urlMatcher instanceof RequestMatcherInterface) {
Expand Down
16 changes: 16 additions & 0 deletions Tests/HttpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,22 @@ public function testCheckRequestPathWithUrlMatcherLoadingException()
$utils->checkRequestPath($this->getRequest(), 'foobar');
}

public function testCheckRequestPathWithRequestAlreadyMatchedBefore()
{
$urlMatcher = $this->createMock(RequestMatcherInterface::class);
$urlMatcher
->expects($this->never())
->method('matchRequest')
;

$request = $this->getRequest();
$request->attributes->set('_route', 'route_name');

$utils = new HttpUtils(null, $urlMatcher);
$this->assertTrue($utils->checkRequestPath($request, 'route_name'));
$this->assertFalse($utils->checkRequestPath($request, 'foobar'));
}

public function testCheckPathWithoutRouteParam()
{
$urlMatcher = $this->createMock(UrlMatcherInterface::class);
Expand Down

0 comments on commit 573ef96

Please sign in to comment.