Skip to content

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

Description

@nikonthethird

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.

Activity

  1. added
    jsJavaScript or TypeScript sources and plugins
    v5v5, the v5-dev branch
    on Feb 17, 2021
  2. nikonthethird commented on Feb 17, 2021

    @nikonthethird
    ContributorAuthor

    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.
    
  3. nikonthethird commented on Feb 17, 2021

    @nikonthethird
    ContributorAuthor

    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.

  4. Microanswer commented on Feb 18, 2021

    @Microanswer

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

  5. nikonthethird commented on Feb 18, 2021

    @nikonthethird
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedReproduced with a reduced test casejsJavaScript or TypeScript sources and pluginsv5v5, the v5-dev branch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions