Commit f6de3381 authored by catch's avatar catch
Browse files

fix: #3637097 Fast 404 is skipped for 404s caused by ParamNotConvertedException

By: eduardo morales alberti
By: smustgrave
(cherry picked from commit 0ab58dee)
parent f0659ed9
Loading
Loading
Loading
Loading
Loading
+4 −1
Changes for core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -88,7 +88,10 @@ public function onException(ExceptionEvent $event) {
   * {@inheritdoc}
   */
  public static function getSubscribedEvents(): array {
    $events[KernelEvents::EXCEPTION][] = ['onException', 75];
    // Run before the fast 404 subscriber (priority 200), so every 404 handler
    // receives a NotFoundHttpException.
    // @see \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber
    $events[KernelEvents::EXCEPTION][] = ['onException', 250];
    return $events;
  }

+19
Changes for core/tests/Drupal/FunctionalTests/EventSubscriber/Fast404Test.php: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
namespace Drupal\FunctionalTests\EventSubscriber;

use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
@@ -28,6 +29,7 @@ class Fast404Test extends BrowserTestBase {
   */
  protected static $modules = [
    'file',
    'image',
    'page_cache',
  ];

@@ -82,6 +84,23 @@ public function testFast404(): void {
    $this->assertSession()->responseHeaderContains('X-Generator', 'Drupal');
  }

  /**
   * Tests fast 404s for routes whose parameters cannot be converted.
   */
  public function testFast404ParamNotConverted(): void {
    // Image style paths are excluded from fast 404s by default.
    // @see https://www.drupal.org/project/drupal/issues/3216687
    $this->config('system.performance')->set('fast_404.exclude_paths', '/\/imagecache\//')->save();

    // An unknown image style fails parameter conversion on a path that
    // matches fast_404.paths.
    $style = ImageStyle::create(['name' => 'does_not_exist', 'label' => 'Does not exist']);
    $this->drupalGet($style->buildUrl('public://fast-404-test.png'));
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSession()->responseNotContains('modules/system/css/');
    $this->assertSession()->pageTextContains('The requested URL');
  }

  /**
   * Tests the fast 404 functionality.
   */