Repository navigation
fix: render cart toggle hidden title label as plain text - #960
Merged
Merged
Conversation
kdaviduik
marked this pull request as ready for review
October 13, 2026 17:42
kdaviduik
marked this pull request as draft
October 13, 2026 19:03
kdaviduik
force-pushed
the
kd-escape-toggle-readable-label
branch
from
October 13, 2026 19:03
be6df04 to
6046ef9
Compare
kdaviduik
marked this pull request as ready for review
October 15, 2026 17:37
tgeselle
approved these changes
Oct 15, 2026
Comment on lines
+32
to
+33
| // This label is appended after Mustache has rendered the main template, so it | ||
| // must be escaped here to keep the title a plain-text option. |
There was a problem hiding this comment.
I think we can remove that comment here
EvilGenius13
approved these changes
Oct 15, 2026
The toggle's visually hidden label interpolated `options.toggle.text.title`
directly into an HTML string. Because that string is appended after Mustache
renders the main template, it bypassed Mustache's escaping, so the title was
parsed as markup instead of text. The visible title path (`contents.title`
enabled) already renders the same value through escaped `{{data.text.title}}`.
Escape the value with `Mustache.escape` before interpolation. This reuses the
escaper the rest of the templates already rely on rather than introducing a
second one, and keeps `readableLabel` returning a string so `wrapTemplate` is
unchanged.
This does not change what screen readers announce. In manual testing, the
announced name came from the toggle wrapper's `aria-label`, which is set via
`setAttribute` and was already treated as plain text.
kdaviduik
marked this pull request as draft
October 16, 2026 02:40
kdaviduik
force-pushed
the
kd-escape-toggle-readable-label
branch
from
October 16, 2026 02:40
6046ef9 to
d086bdb
Compare
kdaviduik
marked this pull request as ready for review
October 16, 2026 02:41
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes https://github.com/shop/issues/issues/84843.
Context
When
options.toggle.contents.titleisfalse(the default), the cart toggle renders a visually hidden label containingoptions.toggle.text.title. That label rendered the title as HTML instead of plain text. The visible title path already renders the same value as text.Root Cause
ToggleView#readableLabelinterpolated the title directly into an HTML string. That string is appended inwrapTemplateafter Mustache has rendered the main template, so it never went through Mustache's escaping before being parsed viainnerHTML.Solution
Escape the title with
Mustache.escape, the same escaper used for{{data.text.title}}in the visible title template. A regression test asserts that markup in the title is not parsed and that the label's text content matches the input exactly.This does not change what screen readers announce. In manual testing, the announced name came from the toggle wrapper's
aria-label, which is set viasetAttributeand was already treated as plain text.Risk Assessment
Low. The only behaviour change is that titles containing HTML or entities (e.g.
&) are no longer parsed as markup in the hidden label, which matches the visible title and thearia-label.