Skip to content

Commit 6b771ff

Browse files
Merge branch '6.3' into 6.4
* 6.3: Fix DBAL 4 compatibility [Cache] Fix ArrayAdapter::freeze() return type Do not match request twice in HttpUtils
2 parents bcf2cc2 + 573ef96 commit 6b771ff

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

HttpUtils.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public function createRequest(Request $request, string $path): Request
107107
public function checkRequestPath(Request $request, string $path): bool
108108
{
109109
if ('/' !== $path[0]) {
110+
// Shortcut if request has already been matched before
111+
if ($request->attributes->has('_route')) {
112+
return $path === $request->attributes->get('_route');
113+
}
114+
110115
try {
111116
// matching a request is more powerful than matching a URL path + context, so try that first
112117
if ($this->urlMatcher instanceof RequestMatcherInterface) {

Tests/HttpUtilsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,22 @@ public function testCheckRequestPathWithUrlMatcherLoadingException()
318318
$utils->checkRequestPath($this->getRequest(), 'foobar');
319319
}
320320

321+
public function testCheckRequestPathWithRequestAlreadyMatchedBefore()
322+
{
323+
$urlMatcher = $this->createMock(RequestMatcherInterface::class);
324+
$urlMatcher
325+
->expects($this->never())
326+
->method('matchRequest')
327+
;
328+
329+
$request = $this->getRequest();
330+
$request->attributes->set('_route', 'route_name');
331+
332+
$utils = new HttpUtils(null, $urlMatcher);
333+
$this->assertTrue($utils->checkRequestPath($request, 'route_name'));
334+
$this->assertFalse($utils->checkRequestPath($request, 'foobar'));
335+
}
336+
321337
public function testCheckPathWithoutRouteParam()
322338
{
323339
$urlMatcher = $this->createMock(UrlMatcherInterface::class);

0 commit comments

Comments
 (0)