Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When setting the title of a View to a string containing a '&', the & gets rendered as & in the Views Preview.
So for example overriding the titles as such (where the title of the nid is 'Apples & Oranges'):
Articles about {{ arguments.nid }}
Renders:
Articles about Apples & Oranges
Where it should render:
Articles about Apples & Oranges
Comments
Comment #2
Lendude@rroose thanks for the report.
Views is in Drupal core now, moving this to the right queue.
Comment #3
lcontreras CreditAttribution: lcontreras commentedThis 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.
Comment #4
lcontreras CreditAttribution: lcontreras commentedComment #5
LendudeJust 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.
Comment #6
lcontreras CreditAttribution: lcontreras commentedHi again,
I'll attach a patch for this issue.
Comment #7
lcontreras CreditAttribution: lcontreras commentedComment #8
rroose CreditAttribution: rroose commentedJust a note: this is happening to me in the preview AND on the actual frontend of the website.
Comment #9
lcontreras CreditAttribution: lcontreras commentedrroose, 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.
Comment #10
dawehnerSome simple test would be great I'd argue.
Comment #11
rroose CreditAttribution: rroose commentedI'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.
Comment #12
lcontreras CreditAttribution: lcontreras commentedI already test it @dawehner, I only reproduce it on the preview and I attached a patch for this.
Comment #13
lcontreras CreditAttribution: lcontreras commentedOk @rroose.
Thank you!!
Comment #14
Lendude@lcontreras thanks for the patch, some feedback:
markup is passed through XSS filter anyway so no need to do that here
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.
Comment #15
lcontreras CreditAttribution: lcontreras commented@Lendude thank you very much for the feedback. I'll keep working on this.
Comment #16
lcontreras CreditAttribution: lcontreras commentedI've attached another patch. I'll try to create the test too.
Comment #17
lcontreras CreditAttribution: lcontreras commentedComment #18
rroose CreditAttribution: rroose commentedI'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.Comment #19
jofitz CreditAttribution: jofitz at ComputerMinds commentedRemoved redundant use statement.
Comment #20
lcontreras CreditAttribution: lcontreras commented@Jo Fitzgerald thanks!
I'll attach an update on the PreviewTest.php file to test this.
Comment #21
lcontreras CreditAttribution: lcontreras commentedComment #22
lcontreras CreditAttribution: lcontreras commentedI've updated my patch for the PreviewTest.php file, because the code should be at the final testPreviewUI() function.
Comment #23
Lendude@lcontreras thanks for keeping at this!
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.
Comment #24
dawehnerComment #25
lcontreras CreditAttribution: lcontreras commented@Lendude thank you. I' ll keep working on this.
Comment #26
lcontreras CreditAttribution: lcontreras commentedAdd a new patch with test and fix.
Comment #27
lcontreras CreditAttribution: lcontreras commentedComment #28
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedre: #23: Using assertNoEscaped seems to be the right choice here.
Patch looks good to me, +1 to RTBC.
Comment #29
LendudeYeah this looks good, we got a fix and we have a test. Nice work
Comment #30
lcontreras CreditAttribution: lcontreras commentedThanks @Lendude for your support!!
Comment #31
catchThis 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.
Comment #32
lcontreras CreditAttribution: lcontreras commented@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.
Comment #33
Lendude@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:
seems to do the trick
Comment #34
lcontreras CreditAttribution: lcontreras commented@Lendude, thanks to explain me this. I'll test it using xpath.
Comment #35
lcontreras CreditAttribution: lcontreras commentedOK, I tested and it's working with the xpath and it shouldn't break the title output when something changes.
Comment #36
lcontreras CreditAttribution: lcontreras commentedComment #37
LendudeNice! Thanks!
Comment #39
lcontreras CreditAttribution: lcontreras commentedFixing coding standards!
Comment #40
lcontreras CreditAttribution: lcontreras commentedComment #41
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedFriendly reminder than not adding interdiffs makes getting a review on your patch a lot harder :)
Here's the interdiff between #35 and #39
Comment #42
LendudeThanks
Comment #43
lcontreras CreditAttribution: lcontreras commentedThanks Lendude and Manuel.
Comment #46
catchI 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!