Skip to content
Snippets Groups Projects
Verified Commit 3116614f authored by Dave Long's avatar Dave Long
Browse files

Issue #3490710 by mfb, catch, spokje: Catch potential exception when calling...

Issue #3490710 by mfb, catch, spokje: Catch potential exception when calling Request::create() in PathBasedBreadcrumbBuilder

(cherry picked from commit c6143563)
parent e539d9bf
No related branches found
No related tags found
1 merge request!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4
Pipeline #364826 passed with warnings
Pipeline: drupal

#364833

    Pipeline: drupal

    #364832

      ......@@ -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;
      ......@@ -211,7 +212,12 @@ protected function getRequestForPath($path, array $exclude) {
      if (!empty($exclude[$path])) {
      return NULL;
      }
      $request = Request::create($path);
      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');
      ......
      ......@@ -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.
      *
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment