Problem/Motivation

Views attachment titles are double escaped.

The title as entered

The title displayed in the admin section of the view.

The title displayed in the preview section.

Note that this issue was committed and reverted.

Steps to reproduce

  1. Create an attachment display for a view
  2. Create a title with special characters
  3. View the title in the preview section of the view

Proposed resolution

TBA

Remaining tasks

Test
Patch
Review
Commit

User interface changes

Yes - Add update to date screeenshots here

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

CommentFileSizeAuthor
#55 2598502-55.patch1.03 KBjmdeleon
#51 Screenshot_2021-11-09 Atest2 (Content) dev0-web(3).png5.01 KBquietone
#51 Screenshot_2021-11-09 Atest2 (Content) dev0-web(1).png2.41 KBquietone
#51 Screenshot_2021-11-09 Atest2 (Content) dev0-web(2).png4.06 KBquietone
#47 string-2598502-46.patch1.03 KBsam-elayyoub
#46 string-2598502-46.patch1.01 KBsam-elayyoub
#45 string-2598502-45.patch1.22 KBsam-elayyoub
#44 string-2598502-44.patch1.2 KBsam-elayyoub
#43 string-2598502-43.patch1.24 KBsam-elayyoub
#42 string-2598502-41.patch1.18 KBsam-elayyoub
#41 string-2598502-41.patch1.27 KBsam-elayyoub
#38 2598502-38.patch10.07 KBbrayfe
#24 interdiff.txt4.97 KBdawehner
#24 2598502-24.patch10.04 KBdawehner
#9 2598502-9.patch5.07 KBalexpott
#9 3-9-interdiff.txt603 bytesalexpott
#3 2598502-3.patch5.05 KBalexpott
#3 2598502-3.test-only.patch4.05 KBalexpott
#2 2598502-2.patch1.58 KBalexpott
#2 2598502-2.test-only.patch595 bytesalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
595 bytes
1.58 KB
alexpott’s picture

The test only patch passed because it was checking for a double escaped & - it should have been checking for a double escaped <.

Added proper testing of this in DisplayAttachmentTest

The last submitted patch, 3: 2598502-3.test-only.patch, failed testing.

dawehner’s picture

+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_attachment_ui.yml
@@ -34,15 +30,47 @@ display:
+          tokenize: false
+          content:
+            value: 'Attachment title: [view:title]'
+            format: plain_text
+          plugin_id: text

Do you mind having a more explicit test for that?

dawehner’s picture

Issue tags: +medium

Tagging for Medium

xjm’s picture

Priority: Major » Normal

The core committers and Views maintainers (alexpott, xjm, effulgentsia, tim.plunkett, and dawehner) agreed that this is not a major issue (despite @alexpott originally filing it as such).

dawehner’s picture

Status: Needs review » Needs work

Needs work due to #5

alexpott’s picture

Status: Needs work » Needs review
FileSize
603 bytes
5.07 KB

Improving the test.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you alex!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 2748b9a on 8.1.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles
    

  • catch committed c01c27e on 8.0.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles...
edurenye’s picture

Status: Fixed » Needs work
+++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
@@ -248,7 +252,7 @@ public function tokenizeValue($value, $row_index) {
       $value = Xss::filterAdmin($value);
     }
-    return $value;
+    return ViewsRenderPipelineMarkup::create($value);
   }
 

This change breaks everything, I have errors like this in some modules, and get's fixed reverting this line.

InvalidArgumentException: $string ("Job overview") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 145 of core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php).
Drupal\Core\StringTranslation\TranslationManager->translate(Object, Array, Array) (Line: 74)
Drupal\Core\Controller\TitleResolver->t(Object, Array, Array) (Line: 71)
Drupal\Core\Controller\TitleResolver->getTitle(Object, Object) (Line: 158)

  • catch committed 491e560 on 8.0.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...
catch’s picture

Version: 8.0.x-dev » 8.1.x-dev

OK reverted from 8.0.x for now.

Leaving this in 8.1.x for a bit longer - can you post a longer backtrace or example code that's triggering this?

edurenye’s picture

The full backtrace:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: $string ("Job overview") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 145 of core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php).
Drupal\Core\StringTranslation\TranslationManager->translate(Object, Array, Array) (Line: 74)
Drupal\Core\Controller\TitleResolver->t(Object, Array, Array) (Line: 71)
Drupal\Core\Controller\TitleResolver->getTitle(Object, Object) (Line: 158)
Drupal\system\PathBasedBreadcrumbBuilder->build(Object) (Line: 88)
Drupal\Core\Breadcrumb\BreadcrumbManager->build(Object) (Line: 77)
Drupal\system\Plugin\Block\SystemBreadcrumbBlock->build() (Line: 207)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 384)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 451)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 59)
__TwigTemplate_999eccb5dced5a7ce436f58b233e3aa534ddbf60db93110b5b36d33caf525f35->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/seven/templates/page.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 468)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 88)
__TwigTemplate_3d56bb3d650d04cb22757e6c1835d86e0100783da675473bc3e3b4231571b121->doDisplay(Array, Array) (Line: 381)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 355)
Twig_Template->display(Array) (Line: 366)
Twig_Template->render(Array) (Line: 64)
twig_render_template('core/themes/classy/templates/layout/html.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 438)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 152)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 153)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 95)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 116)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 103)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 637)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I was opening a form that changes the title and adds breadcrumbs.
It was in TMGMT but also it happened to a coworker that was working in this Core issue #2640994: Label token replacement for views entity reference arguments not working

tduong’s picture

Debugged and if you do a string cast on '_title' => (string) $this->view->getTitle(), in \Drupal\views\Plugin\views\display\PathPluginBase::getRoute() (line 137) it fixes the bug.

  • catch committed a173d72 on 8.1.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...
catch’s picture

Issue tags: +Needs tests

OK that looks like we're missing some core test coverage then. Reverted from 8.1.x as well.

Berdir’s picture

Yes, we do, no idea why none of our tests are failing.

Also, it's wrong that this string is being translated in the first place. It is user provided data and shouldn't be run through t(). That's an existing problem but it might be the proper way to solve this. TitleResolver::getTitle() needs a way to not run _title through t(), based on some flag I guess.

Or views needs to use a _title_callback instead.

dawehner’s picture

@edurenye @berdir
Do you mind providing the view which caused the issue?

_title_callback

Well, in general we cannot do that for everything as the computational overhead would be too crazy. We though add some static title in there:

  protected function getRoute($view_id, $display_id) {
    $defaults = array(
      '_controller' => 'Drupal\views\Routing\ViewPageController::handle',
      '_title' => $this->view->getTitle(),
      'view_id' => $view_id,
      'display_id' => $display_id,
      '_view_display_show_admin_links' => $this->getOption('show_admin_links'),
    );
Berdir’s picture

To reproduce, just apply the patch, clear cache and go to d8/admin/content/comment. Boom. Any page that has a view in the path parents causes this.

swentel’s picture

I've hit this as well on admin/content - but not sure how I got it like that. I have a dump where it fails, but after simply clearing cache or saving the view without changing anything it's fine. Will try this patch on to see if it's ok without clearing the cache.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • catch committed 2748b9a on 8.3.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles
    
  • catch committed a173d72 on 8.3.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...

  • catch committed 2748b9a on 8.3.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles
    
  • catch committed a173d72 on 8.3.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Berdir’s picture

Do we need explicit (web) test coverage for that bug?

dawehner’s picture

Status: Needs review » Needs work

Yeah I guess @berdir is totally right here.

  • catch committed 2748b9a on 8.4.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles
    
  • catch committed a173d72 on 8.4.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...

  • catch committed 2748b9a on 8.4.x
    Issue #2598502 by alexpott: Double escaping in views attachment titles
    
  • catch committed a173d72 on 8.4.x
    Revert "Issue #2598502 by alexpott: Double escaping in views attachment...

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

brayfe’s picture

FileSize
10.07 KB

Running into this issue with a specific Media Library view in 8.6.4 and hoping this patch will fix it. Since the patch didn't apply cleanly for 8.6.4, I re-rolled it.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sam-elayyoub’s picture

this is a patch I used to make it work but it works :-) simply convert if it's not string to string.

sam-elayyoub’s picture

sam-elayyoub’s picture

The core was there my bad in the path here's the new one

sam-elayyoub’s picture

sam-elayyoub’s picture

sam-elayyoub’s picture

works on composer the last patch but here's the one that works on jenkins

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Thanks to danflanagan8 for teaching what a Views 'attachment' is.

I tested this on 9.3.x, standard install, and the problem persists. One thing that was unexpected is the title is not displayed on the view, only on the preview of the attachment.

Not sure if this should be in the view_ui component or not.

Lendude’s picture

We did a pretty generic fix here, #2872322: Views preview title is double escaped, so a little surprised that attachments are still broken

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jmdeleon’s picture

Re-rolling patch in #47 to use PHP __toString() method to get a cleaner string representation versus an object serialization.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.