Skip to content
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

<img> inside HTML tooltip is only displayed every other hover. #33124

Closed
nikonthethird opened this issue Feb 16, 2021 · 4 comments · Fixed by #33136
Closed

<img> inside HTML tooltip is only displayed every other hover. #33124

nikonthethird opened this issue Feb 16, 2021 · 4 comments · Fixed by #33136

Comments

@nikonthethird
Copy link
Contributor

Reproduction:

https://jsfiddle.net/3k4cL51w/

Steps:

The Test button has a tooltip with data-bs-html="true" on it and an <img> tag in the title. When you hover your mouse multiple times over the button, you will see that the the image in the tooltip will only be shown every other hover.

I tested this on Ubuntu 20.04 on Firefox and Chromium.
It worked on 5.0 beta 1, the issue only started appearing after I upgraded to 5.0 beta 2.

@nikonthethird
Copy link
Contributor Author

nikonthethird commented Feb 17, 2021

I investigated some more, and it appears to have to do with sanitization. When I initialize the tooltips with sanitize set to false, it does not happen:

new bootstrap.Tooltip(element, { sanitize: false }) // This fixes it.

@nikonthethird
Copy link
Contributor Author

I figured out what's wrong. This commit switched from using the match method on strings to the test method of the SAFE_URL_PATTERN regex.

Well, the match and test methods behave differently. The problem is the g (global) modifier. See the example here to see that the test method returns true, then false when presented with the same string:

// This is the regex that's causing the problem.
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/gi

To fix the issue, simply remove the g modifier (which, btw is not present on the DATA_URL_PATTERN regex, so no issue there). Furthermore, the regex is faulty, because slashes have to be escaped with a backslash (see here).

The correct regex would be:

const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&\/:?]*(?:[#\/?]|$))/i

And that fixes the issue on my end and I can leave the sanitizer turned on. I'll make a pull request if that's ok.

@Microanswer
Copy link

我也遇到相同的问题,看了你这波操作属实流弊,所以我就直接借用了。
I had the same issues, thanks your idea.

@nikonthethird
Copy link
Contributor Author

I opened an issue over at the eslint unicorn plugin so that the rule that introduced this bug can get fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants