From 894edeb8d2ced5c37b61ba9e0adcfa3a43bea062 Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Mon, 11 Nov 2024 16:11:15 +0000 Subject: [PATCH] Issue #3486195 by longwave, alexpott, dmundra: An update to symfony/http-foundation plus a trailing space took down the views UI (cherry picked from commit ea71ff8bd8341f07e0d395b2d52eaaff55b11a20) --- core/modules/views_ui/src/ViewEditForm.php | 5 +++-- core/modules/views_ui/src/ViewListBuilder.php | 5 +++-- .../config/install/views.view.sa_contrib_2013_035.yml | 2 +- core/modules/views_ui/tests/src/Functional/XssTest.php | 2 ++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 93dc5c88984d..6ab9c36138af 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -16,6 +16,7 @@ use Drupal\Core\Url; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -464,7 +465,7 @@ public function getDisplayDetails($view, $display) { if ($path && (!str_contains($path, '%'))) { // Wrap this in a try/catch as trying to generate links to some - // routes may throw a NotAcceptableHttpException if they do not + // routes may throw an exception, for example if they do not // respond to HTML, such as RESTExports. try { if (!parse_url($path, PHP_URL_SCHEME)) { @@ -476,7 +477,7 @@ public function getDisplayDetails($view, $display) { $url = Url::fromUri("base:$path"); } } - catch (NotAcceptableHttpException $e) { + catch (BadRequestException | NotAcceptableHttpException $e) { $url = '/' . $path; } diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index b494fbc78c3d..9bb1bf9cd48d 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -10,6 +10,7 @@ use Drupal\Core\Link; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; /** @@ -261,14 +262,14 @@ protected function getDisplaysList(EntityInterface $view) { $path = $display->getPath(); if ($view->status() && !str_contains($path, '%')) { // Wrap this in a try/catch as trying to generate links to some - // routes may throw a NotAcceptableHttpException if they do not + // routes may throw an exception, for example if they do not // respond to HTML, such as RESTExports. try { // @todo Views should expect and store a leading /. See: // https://www.drupal.org/node/2423913 $rendered_path = Link::fromTextAndUrl('/' . $path, Url::fromUserInput('/' . $path))->toString(); } - catch (NotAcceptableHttpException $e) { + catch (BadRequestException | NotAcceptableHttpException $e) { $rendered_path = '/' . $path; } } diff --git a/core/modules/views_ui/tests/modules/views_ui_test/config/install/views.view.sa_contrib_2013_035.yml b/core/modules/views_ui/tests/modules/views_ui_test/config/install/views.view.sa_contrib_2013_035.yml index 80029fb944ac..d6280799790c 100644 --- a/core/modules/views_ui/tests/modules/views_ui_test/config/install/views.view.sa_contrib_2013_035.yml +++ b/core/modules/views_ui/tests/modules/views_ui_test/config/install/views.view.sa_contrib_2013_035.yml @@ -183,4 +183,4 @@ display: display_plugin: page position: 2 display_options: - path: foobar + path: 'foobar ' diff --git a/core/modules/views_ui/tests/src/Functional/XssTest.php b/core/modules/views_ui/tests/src/Functional/XssTest.php index 73cc00b81777..bb20f9c7bb90 100644 --- a/core/modules/views_ui/tests/src/Functional/XssTest.php +++ b/core/modules/views_ui/tests/src/Functional/XssTest.php @@ -37,6 +37,8 @@ public function testViewsUi() { */ public function testNoDoubleEscaping() { $this->drupalGet('admin/structure/views'); + $this->assertSession()->pageTextContains('sa_contrib_2013_035'); + $this->assertSession()->pageTextContains('Page (/foobar )'); $this->assertSession()->assertNoEscaped('<'); $this->drupalGet('admin/structure/views/view/sa_contrib_2013_035'); -- GitLab