[tfjs-vis] Escape HTML in heatmap tooltip labels#8717
Open
f0r wants to merge 1 commit into
Open
Conversation
When `xTickLabels`/`yTickLabels` are supplied, `render.heatmap` installs a custom vega-tooltip `sanitize` function to strip an internal index suffix. Supplying a custom `sanitize` bypasses vega-tooltip's default `escapeHTML`, so tick-label strings were inserted into the tooltip as raw HTML instead of text. Re-apply HTML escaping after stripping the suffix so labels render as text, matching vega-tooltip's default behavior. Extract the escaping into an `escapeHTML` helper and add unit tests.
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.
What
render.heatmapescapes HTML in tooltip tick labels so that label stringsare rendered as text rather than markup.
Why
When
xTickLabels/yTickLabelsare supplied,render.heatmapinstalls acustom
vega-tooltipsanitizefunction to strip an internal index suffixescapeHTML, so the tick-label string is written into the tooltip element viainnerHTMLwithout escaping. A label such as<img src=x onerror=...>istherefore parsed as live HTML in the tooltip.
This restores the escaping
vega-tooltipapplies by default, while keeping theexisting index-suffix stripping.
Changes
sanitize.escapeHTMLhelper.escapeHTML.I've signed the Google CLA.