Loading core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php +1 −1 Changes for core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); // Only care about HTML responses. if (stripos($response->headers->get('Content-Type', ''), 'text/html') === FALSE) { if (stripos($response->headers->get('Content-Type') ?? '', 'text/html') === FALSE) { return; } Loading core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php +1 −1 Changes for core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class RssResponseRelativeUrlFilter implements EventSubscriberInterface { */ public function onResponse(ResponseEvent $event) { // Only care about RSS responses. if (stripos($event->getResponse()->headers->get('Content-Type', ''), 'application/rss+xml') === FALSE) { if (stripos($event->getResponse()->headers->get('Content-Type') ?? '', 'application/rss+xml') === FALSE) { return; } Loading core/modules/jsonapi/tests/modules/jsonapi_response_validator/src/EventSubscriber/ResourceResponseValidator.php +1 −1 Changes for core/modules/jsonapi/tests/modules/jsonapi_response_validator/src/EventSubscriber/ResourceResponseValidator.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ public static function getSubscribedEvents(): array { */ public function onResponse(ResponseEvent $event): void { $response = $event->getResponse(); if (!str_contains($response->headers->get('Content-Type', ''), 'application/vnd.api+json')) { if (!str_contains($response->headers->get('Content-Type') ?? '', 'application/vnd.api+json')) { return; } Loading core/modules/jsonapi/tests/modules/jsonapi_response_validator/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +20 −0 Changes for core/modules/jsonapi/tests/modules/jsonapi_response_validator/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ use PHPUnit\Framework\Attributes\Group; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** * Tests Drupal\jsonapi_response_validator\EventSubscriber\ResourceResponseValidator. Loading Loading @@ -200,4 +202,22 @@ protected static function createResponse(?string $json = NULL): ResourceResponse return $response; } /** * Tests that a response with a NULL Content-Type header is ignored. */ public function testOnResponseNullContentType(): void { $response = static::createResponse(); $response->headers->set('Content-Type', NULL); $event = new ResponseEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), new Request(), HttpKernelInterface::MAIN_REQUEST, $response ); $this->subscriber->onResponse($event); $this->assertNull($event->getResponse()->headers->get('Content-Type')); } } core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php +52 −0 Changes for core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -880,6 +880,58 @@ public function testOnlyHtml(): void { $this->assertSame($response->getContent(), $content); } /** * Tests a response with a NULL Content-Type header is ignored. * * @legacy-covers ::onResponse */ public function testOnResponseNullContentType(): void { $session = new AnonymousUserSession(); $language_manager = new LanguageManager(new LanguageDefault([])); $request_stack = new RequestStack(); $request_stack->push(new Request()); $current_path_stack = new CurrentPathStack($request_stack); // Make sure path matcher isn't called and we didn't get to the link logic. $path_matcher = $this->prophesize(PathMatcherInterface::class); $path_matcher->isFrontPage()->shouldNotBeCalled(); $subscriber = new ActiveLinkResponseFilter( $session, $current_path_stack, $path_matcher->reveal(), $language_manager ); // A header can be present with a NULL value, which HeaderBag::get() // returns in place of the default. Passing that to stripos() raises a // deprecation rather than throwing, so promote it to an exception. $content = '<a data-drupal-link-system-path="other-page">Other page</a>'; $response = new Response(); $response->setContent($content); $response->headers->set('Content-Type', NULL); set_error_handler( static function (int $severity, string $message): never { throw new \ErrorException($message, 0, $severity); }, E_DEPRECATED ); try { $subscriber->onResponse(new ResponseEvent( $this->prophesize(KernelInterface::class)->reveal(), $request_stack->getCurrentRequest(), HttpKernelInterface::MAIN_REQUEST, $response )); } finally { restore_error_handler(); } $this->assertSame($content, $response->getContent()); } /** * Tests certain response types ignored by the ActiveLinkResponseFilter. * Loading Loading
core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php +1 −1 Changes for core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); // Only care about HTML responses. if (stripos($response->headers->get('Content-Type', ''), 'text/html') === FALSE) { if (stripos($response->headers->get('Content-Type') ?? '', 'text/html') === FALSE) { return; } Loading
core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php +1 −1 Changes for core/lib/Drupal/Core/EventSubscriber/RssResponseRelativeUrlFilter.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ class RssResponseRelativeUrlFilter implements EventSubscriberInterface { */ public function onResponse(ResponseEvent $event) { // Only care about RSS responses. if (stripos($event->getResponse()->headers->get('Content-Type', ''), 'application/rss+xml') === FALSE) { if (stripos($event->getResponse()->headers->get('Content-Type') ?? '', 'application/rss+xml') === FALSE) { return; } Loading
core/modules/jsonapi/tests/modules/jsonapi_response_validator/src/EventSubscriber/ResourceResponseValidator.php +1 −1 Changes for core/modules/jsonapi/tests/modules/jsonapi_response_validator/src/EventSubscriber/ResourceResponseValidator.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ public static function getSubscribedEvents(): array { */ public function onResponse(ResponseEvent $event): void { $response = $event->getResponse(); if (!str_contains($response->headers->get('Content-Type', ''), 'application/vnd.api+json')) { if (!str_contains($response->headers->get('Content-Type') ?? '', 'application/vnd.api+json')) { return; } Loading
core/modules/jsonapi/tests/modules/jsonapi_response_validator/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +20 −0 Changes for core/modules/jsonapi/tests/modules/jsonapi_response_validator/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ use PHPUnit\Framework\Attributes\Group; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; /** * Tests Drupal\jsonapi_response_validator\EventSubscriber\ResourceResponseValidator. Loading Loading @@ -200,4 +202,22 @@ protected static function createResponse(?string $json = NULL): ResourceResponse return $response; } /** * Tests that a response with a NULL Content-Type header is ignored. */ public function testOnResponseNullContentType(): void { $response = static::createResponse(); $response->headers->set('Content-Type', NULL); $event = new ResponseEvent( $this->prophesize(HttpKernelInterface::class)->reveal(), new Request(), HttpKernelInterface::MAIN_REQUEST, $response ); $this->subscriber->onResponse($event); $this->assertNull($event->getResponse()->headers->get('Content-Type')); } }
core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php +52 −0 Changes for core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php: 52 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -880,6 +880,58 @@ public function testOnlyHtml(): void { $this->assertSame($response->getContent(), $content); } /** * Tests a response with a NULL Content-Type header is ignored. * * @legacy-covers ::onResponse */ public function testOnResponseNullContentType(): void { $session = new AnonymousUserSession(); $language_manager = new LanguageManager(new LanguageDefault([])); $request_stack = new RequestStack(); $request_stack->push(new Request()); $current_path_stack = new CurrentPathStack($request_stack); // Make sure path matcher isn't called and we didn't get to the link logic. $path_matcher = $this->prophesize(PathMatcherInterface::class); $path_matcher->isFrontPage()->shouldNotBeCalled(); $subscriber = new ActiveLinkResponseFilter( $session, $current_path_stack, $path_matcher->reveal(), $language_manager ); // A header can be present with a NULL value, which HeaderBag::get() // returns in place of the default. Passing that to stripos() raises a // deprecation rather than throwing, so promote it to an exception. $content = '<a data-drupal-link-system-path="other-page">Other page</a>'; $response = new Response(); $response->setContent($content); $response->headers->set('Content-Type', NULL); set_error_handler( static function (int $severity, string $message): never { throw new \ErrorException($message, 0, $severity); }, E_DEPRECATED ); try { $subscriber->onResponse(new ResponseEvent( $this->prophesize(KernelInterface::class)->reveal(), $request_stack->getCurrentRequest(), HttpKernelInterface::MAIN_REQUEST, $response )); } finally { restore_error_handler(); } $this->assertSame($content, $response->getContent()); } /** * Tests certain response types ignored by the ActiveLinkResponseFilter. * Loading