-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Limit what tooltip content may render #25250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sgiehl
wants to merge
4
commits into
6.x-dev
Choose a base branch
from
harden-tooltip-sanitizer
base: 6.x-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34efeae
Limit what tooltip content may render
sgiehl 51d470b
Escape the values rendered into tooltip titles
sgiehl ca1ee2d
Show a tooltip title in full where part of it could be dropped
sgiehl cd562ea
Escape tooltip titles independently of what the producer escaped
sgiehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /*! | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| import tooltipContent from './tooltipContent'; | ||
|
|
||
| // The sanitizer itself lives in the polyfill bundle, so it is stubbed with an identity function | ||
| // here - these tests cover what the helper does around it. | ||
| const sanitize = vi.fn((value: unknown) => `${value}`); | ||
|
|
||
| (window as unknown as { vueSanitizeTooltip: unknown }).vueSanitizeTooltip = sanitize; | ||
|
|
||
| function element(title?: string): HTMLElement { | ||
| const el = document.createElement('span'); | ||
| if (typeof title !== 'undefined') { | ||
| el.setAttribute('title', title); | ||
| } | ||
| return el; | ||
| } | ||
|
|
||
| describe('CoreHome/tooltipContent', () => { | ||
| beforeEach(() => { | ||
| sanitize.mockClear(); | ||
| }); | ||
|
|
||
| it('sanitizes the title of the element it is called on', () => { | ||
| expect(tooltipContent.call(element('a title'))).toEqual('a title'); | ||
| expect(sanitize).toHaveBeenCalledWith('a title'); | ||
| }); | ||
|
|
||
| it('hands the title over unchanged, line breaks included', () => { | ||
| tooltipContent.call(element('first\nsecond')); | ||
| expect(sanitize).toHaveBeenCalledWith('first\nsecond'); | ||
| }); | ||
|
|
||
| it('passes an empty string if there is no title', () => { | ||
| expect(tooltipContent.call(element())).toEqual(''); | ||
| expect(sanitize).toHaveBeenCalledWith(''); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /*! | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| /** | ||
| * Content transform for jQuery UI tooltips that show the `title` of the hovered element. | ||
| * | ||
| * Meant to be passed as the widget's `content` option, so it is called with the target element as | ||
| * `this`. | ||
| * | ||
| * jQuery UI inserts what we return with `.html()`, and the browser has already decoded the | ||
| * attribute, so the value is parsed as HTML a second time. It therefore goes through the tooltip | ||
| * sanitizer rather than the general one, which also turns the title's line breaks into `<br />`. | ||
| */ | ||
| export default function tooltipContent(this: HTMLElement): string { | ||
| return window.vueSanitizeTooltip(this.getAttribute('title') || ''); | ||
| } |
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
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
4 changes: 2 additions & 2 deletions
4
plugins/CoreVisualizations/templates/_dataTableViz_tagCloud.twig
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.