Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rroose created an issue. See original summary.

Lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.4.x-dev
Component: Miscellaneous » views.module

@rroose thanks for the report.

Views is in Drupal core now, moving this to the right queue.

lcontreras’s picture

FileSize
89.34 KB
73.12 KB

This is only happening on the preview of the view. I followed these steps:

- Created a view to show articles content
- Add a contextual filter Content: ID and override Title {{arguments.nid}}.
- Then I testest the preview and It was ok, except the first title (you can see it on the image attached).
- I also created a view page from the master view to test the page and it working fine.

Please let me know if I am missing something.

Thank you.

lcontreras’s picture

Assigned: Unassigned » lcontreras
Lendude’s picture

Title: Overriding title with contextual filter renders & instead of & » Views preview title is double escaped
Component: views.module » views_ui.module
Priority: Normal » Minor

Just tested this and it has nothing to do with the token, if you just set the title of the View to 'double & escaped' it also gets double escaped.

So yeah this is definitely bugged, but setting to minor as it is only the preview.

lcontreras’s picture

Hi again,

I'll attach a patch for this issue.

lcontreras’s picture

Status: Active » Needs review
rroose’s picture

Just a note: this is happening to me in the preview AND on the actual frontend of the website.

lcontreras’s picture

rroose, when you say that happend to you on the frontend, I guess you mean the title of the view not the title of the node. Could you attach a file?, because I can only reproduce on the preview and the frontend (view page) but only with the view title.

Thank you.

dawehner’s picture

Some simple test would be great I'd argue.

rroose’s picture

I've tested it with a clean Drupal 8 installation and it seems to work correctly now. I will update the website that was having the problem to the newest Drupal version and test again. Hopefully it will be resolved. I will report back if it isn't.

lcontreras’s picture

I already test it @dawehner, I only reproduce it on the preview and I attached a patch for this.

lcontreras’s picture

Ok @rroose.

Thank you!!

Lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@lcontreras thanks for the patch, some feedback:

  1. +++ b/core/modules/views_ui/src/ViewUI.php
    @@ -688,7 +688,11 @@ public function renderPreview($display_id, $args = []) {
    +                  '#markup' => Xss::filterAdmin($executable->getTitle()),
    

    markup is passed through XSS filter anyway so no need to do that here

  2. +++ b/core/modules/views_ui/src/ViewUI.php
    @@ -688,7 +688,11 @@ public function renderPreview($display_id, $args = []) {
    +              ]
    

    missing trailing comma

Also @dawehner in #10 was referring to automated tests, not manual tests. This is a bug so we need to add an automated test for this, to make sure it stays fixed.

lcontreras’s picture

@Lendude thank you very much for the feedback. I'll keep working on this.

lcontreras’s picture

I've attached another patch. I'll try to create the test too.

lcontreras’s picture

Status: Needs work » Needs review
rroose’s picture

I've updated the website but the problem still persist. Also the problem is not exactly as described above. It occurs when you use [view:title] in the head of your view.

jofitz’s picture

Removed redundant use statement.

lcontreras’s picture

@Jo Fitzgerald thanks!

I'll attach an update on the PreviewTest.php file to test this.

lcontreras’s picture

Issue tags: -Needs tests +Needs Review
lcontreras’s picture

I've updated my patch for the PreviewTest.php file, because the code should be at the final testPreviewUI() function.

Lendude’s picture

Issue tags: -Needs Review

@lcontreras thanks for keeping at this!

+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -114,6 +114,10 @@ public function testPreviewUI() {
+    //Test preview title double escaped

Well we need a test that it isn't double escaped, so I would make the comment
"Test that the preview title isn't double escaped.".
Also the comment needs a space after the // and a period at the end.

Also the test needs an actual assertion at the end, so we can show that it fails without the fix and passes with the fix.

So we'd need to add $this->assertText('Double & escaped'); at the end.

And then we would need a patch that contains both the test and the fix.

dawehner’s picture

Status: Needs review » Needs work
lcontreras’s picture

@Lendude thank you. I' ll keep working on this.

lcontreras’s picture

Add a new patch with test and fix.

lcontreras’s picture

Status: Needs work » Needs review
Manuel Garcia’s picture

re: #23: Using assertNoEscaped seems to be the right choice here.
Patch looks good to me, +1 to RTBC.

Lendude’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Yeah this looks good, we got a fix and we have a test. Nice work

lcontreras’s picture

Thanks @Lendude for your support!!

catch’s picture

Version: 8.4.x-dev » 8.3.x-dev
Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -114,6 +114,11 @@ public function testPreviewUI() {
+
+    // Test that the preview title isn't double escaped.
+    $this->drupalPostForm("admin/structure/views/nojs/display/test_preview/default/title", $edit = ['title' => 'Double & escaped'], t('Apply'));
+    $this->drupalPostForm(NULL, [], t('Update preview'));
+    $this->assertNoEscaped('Double & escaped');

This looks great except I think we should use the positive assertion from #23 here $this->assertText('Double & escaped');

assertNoEscaped() only checks for the absence of text, so if there was an additional bug that titles weren't displaying at all, the test could still pass as it is now.

It's also useful to post two patches - one with only the test additions (that the automated tests will show as failing) and one with both test and fix.

lcontreras’s picture

@Cath thanks to see this. Well, I don't think $this->assertText(); is the rigth assertion to use because the test always fails using it: $this->assertText('Double & escaped'). And we can't use it like this $this->assertText('Double & escaped'); because it always pass event when the fix is not applied. With this assertion $this->assertNoEscaped the test fail withouth the fix and pass with the fix.

Lendude’s picture

@lcontreras the point that @catch makes is very valid (and I should have spotted it). Only having a negative assertion isn't really useful. Some other change could completely break the title output, but our test would still pass as long as it didn't change it to 'Double & escaped'.

So we need a positive assertion here. And with the addition of a positive assertion, the negative assertion can be taken out.

$this->assertText('Double & escaped'); always passes (even without the fix), because that text is available elsewhere on the page. So we need a test that specifically targets our preview title.

Since we don't have a lot of css classes to work with here, xpath would probably be the best way to do this:

    $elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', array(':text' => t('Double & escaped')));
    $this->assertEqual(1, count($elements));

seems to do the trick

lcontreras’s picture

@Lendude, thanks to explain me this. I'll test it using xpath.

lcontreras’s picture

OK, I tested and it's working with the xpath and it shouldn't break the title output when something changes.

lcontreras’s picture

Status: Needs work » Needs review
Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Nice! Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: Views_preview_title_is_double_escaped-2872322-35.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lcontreras’s picture

lcontreras’s picture

Status: Needs work » Needs review
Manuel Garcia’s picture

FileSize
1.37 KB

Friendly reminder than not adding interdiffs makes getting a review on your patch a lot harder :)

Here's the interdiff between #35 and #39

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

lcontreras’s picture

Thanks Lendude and Manuel.

  • catch committed 193c484 on 8.4.x
    Issue #2872322 by lcontreras, Jo Fitzgerald, Manuel Garcia, Lendude,...

  • catch committed 448d6d8 on 8.3.x
    Issue #2872322 by lcontreras, Jo Fitzgerald, Manuel Garcia, Lendude,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

I missed that the text appears elsewhere on the page, that's a good point and the xpath assertion is great.

Committed/pushed to 8.4.x and cherry-picked to 8.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.