fix(tooltip): reset escaped content without innerHTML - #1418
Open
jase88 wants to merge 1 commit into
Open
Conversation
Assigning a plain string to innerHTML throws under a Trusted Types CSP
("This document requires 'TrustedHTML' assignment"). Clearing the
tooltip text via textContent has the same effect without triggering the
policy.
Fixes openng-org#223
Contributor
Author
|
@geromegrignon @dominicbachmann |
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.
Fixes #223
Problem
With a Trusted Types CSP (
require-trusted-types-for 'script'), showing a tooltip throws:Tooltip.updateText()assigned an empty string toinnerHTMLpurely to clear previously rendered text before appending the escaped text node. Trusted Types rejects any plain-stringinnerHTMLassignment, including the empty one.Change
Clear the tooltip text with
textContent = ''instead. Same effect (removes all child nodes), no Trusted Types violation.The
escape: falsebranch still assignsinnerHTML— that path intentionally renders HTML and is out of scope here.Test
Added a unit test that makes
innerHTMLthrow on the tooltip text element (mimicking a Trusted Types document) and assertsupdateText()still replaces the previous content.ng test optimus-ui --include='**/tooltip/tooltip.spec.ts'→ 45/45 passing.