Problem/Motivation

Tab titles containing special characters such as "&" are rendered as literal "&" in the browser instead of the intended character. The issue is a double HTML-encoding chain in QuickTabs.php.

Steps to reproduce

1. Create a Quicktabs instance with a tab title that contains an ampersand, e.g. Meetings & Events.
2. Place the block on a page and view it.
3. Observe the tab label renders as "Meetings & Events" instead of "Meetings & Events".

Proposed resolution

Remove the t('@title', ...) wrapper (stored tab titles are not translatable strings) and wrap the Xss::filter() result in Markup::create() so that Link::fromTextAndUrl() recognizes it as already-sanitized HTML. Also add the required "use Drupal\Core\Render\Markup;" statement.

User interface changes

Tab titles with special characters (&, <, >, quotes) will now render correctly instead of showing escaped HTML entities.

Issue fork quicktabs-3588550

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lucuella created an issue. See original summary.

lucuella’s picture

StatusFileSize
new780 bytes

Attaching patch against 4.1.0. The fix removes the t('@title', [...]) wrapper that was causing the first encoding pass, and wraps the Xss::filter() result in Markup::create() so Link::fromTextAndUrl() does not escape it a second time.

lucuella’s picture

Status: Active » Needs review
joelpittet’s picture

Version: 4.1.0 » 4.0.x-dev
Assigned: lucuella » Unassigned
Status: Needs review » Closed (duplicate)

Moving to the dev branch. We really should see the patch in an MR.

This also feels like deja vu, maybe I fixed this already in dev? Currently doesn't apply. It should have been fixed in #3545740: Tab Title HTML encoding issue

If it's still an issue please let me know and we can re-open this.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joelpittet’s picture

Status: Closed (duplicate) » Needs work

I'm still seeing this actually, darn re-opening. Need to move to an MR

joelpittet’s picture

Priority: Normal » Minor
Status: Needs work » Fixed

Thank you @lucuella there was indeed a missing spot that wasn't fixed by the other issue. I will commit the fix and a regression test in a moment.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

joelpittet’s picture

This is interesting, I am getting an AI to do the fix, but I am very familiar with double escaping as I was heavily involved in this part of Drupal 8 development more than a decade ago! See #1825952: Turn on twig autoescape by default for creds.

It first tried to flatten the label to a string, render it with PlainTextOutput from HTML then concatinate it... but you don't need to flatten or change it to not HTML, just let the pre-existing MarkupInterface object keep holding on and pass that to an @param... it will recognize it's already been "marked safe" and not double escape it. As soon as you flatten it, it will rightly lose trust.

/rant

joelpittet’s picture

Priority: Minor » Normal

On the other hand it finds things I can't...
Wrap the grouping tab title in Markup::create() so Link does not re-encode the Xss::filter() output (e.g. "&amp;" -> "&amp;amp;"). Add the missing views.style.quicktabs config schema and a functional regression test.

  • joelpittet committed 785d6e48 on 4.0.x
    fix: #3588550 Tab titles with special characters (like "...

Status: Fixed » Closed (fixed)

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