Issue #3486195 by longwave, alexpott, dmundra: An update to symfony/http-foundation plus a trailing space took down the views UI

merge-requests/4540/merge
catch 2024-11-11 15:25:47 +00:00
parent 94bc96150c
commit 2810f72c57
4 changed files with 9 additions and 5 deletions

View File

@ -16,6 +16,7 @@ use Drupal\Core\Theme\ThemeManagerInterface;
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 @@ class ViewEditForm extends ViewFormBase {
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 @@ class ViewEditForm extends ViewFormBase {
$url = Url::fromUri("base:$path");
}
}
catch (NotAcceptableHttpException) {
catch (BadRequestException | NotAcceptableHttpException) {
$url = '/' . $path;
}

View File

@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
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 @@ class ViewListBuilder extends ConfigEntityListBuilder {
$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) {
catch (BadRequestException | NotAcceptableHttpException) {
$rendered_path = '/' . $path;
}
}

View File

@ -183,4 +183,4 @@ display:
display_plugin: page
position: 2
display_options:
path: foobar
path: 'foobar '

View File

@ -37,6 +37,8 @@ class XssTest extends UITestBase {
*/
public function testNoDoubleEscaping(): void {
$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');