Loading core/modules/system/src/PathBasedBreadcrumbBuilder.php +7 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; Loading Loading @@ -211,7 +212,12 @@ protected function getRequestForPath($path, array $exclude) { if (!empty($exclude[$path])) { return NULL; } try { $request = Request::create($path); } catch (BadRequestException) { return NULL; } // Performance optimization: set a short accept header to reduce overhead in // AcceptHeaderMatcher when matching the request. $request->headers->set('Accept', 'text/html'); Loading core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +22 −0 Original line number Diff line number Diff line Loading @@ -336,6 +336,28 @@ public function testBuildWithNonProcessedPath(): void { $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge()); } /** * Tests the build method with an invalid path. * * @covers ::build * @covers ::getRequestForPath */ public function testBuildWithInvalidPath(): void { // The parse_url() function returns FALSE for '/:123/foo' so the // Request::create() method therefore considers it to be an invalid URI. $this->context->expects($this->once()) ->method('getPathInfo') ->willReturn('/:123/foo/bar'); $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface')); // No path matched, though at least the frontpage is displayed. $this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks()); $this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts()); $this->assertEqualsCanonicalizing([], $breadcrumb->getCacheTags()); $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge()); } /** * Tests the applied method. * Loading Loading
core/modules/system/src/PathBasedBreadcrumbBuilder.php +7 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; Loading Loading @@ -211,7 +212,12 @@ protected function getRequestForPath($path, array $exclude) { if (!empty($exclude[$path])) { return NULL; } try { $request = Request::create($path); } catch (BadRequestException) { return NULL; } // Performance optimization: set a short accept header to reduce overhead in // AcceptHeaderMatcher when matching the request. $request->headers->set('Accept', 'text/html'); Loading
core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +22 −0 Original line number Diff line number Diff line Loading @@ -336,6 +336,28 @@ public function testBuildWithNonProcessedPath(): void { $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge()); } /** * Tests the build method with an invalid path. * * @covers ::build * @covers ::getRequestForPath */ public function testBuildWithInvalidPath(): void { // The parse_url() function returns FALSE for '/:123/foo' so the // Request::create() method therefore considers it to be an invalid URI. $this->context->expects($this->once()) ->method('getPathInfo') ->willReturn('/:123/foo/bar'); $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface')); // No path matched, though at least the frontpage is displayed. $this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks()); $this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts()); $this->assertEqualsCanonicalizing([], $breadcrumb->getCacheTags()); $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge()); } /** * Tests the applied method. * Loading