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

Popover + Tooltip - fix error when content or title is a number #22316

Merged
merged 3 commits into from
Mar 31, 2017

Conversation

Johann-S
Copy link
Member

@Johann-S Johann-S commented Mar 30, 2017

As @cvrebert suggest (#20210 (comment)) convert content and title to string

Close #20193

@Johann-S Johann-S added this to the v4.0.0-beta milestone Mar 30, 2017
@pvdlg
Copy link
Contributor

pvdlg commented Mar 30, 2017

I don't think it's the right fix. What you are doing is preemptively converting the data-title and data-content to string, effectively you are bypassing the checks done in Util.typeCheckConfig.
I think that checks were put in place for a reason (I guess controlling the content to avoid XSS).
Moreover the data-title and data-content can be an element or a function and you are converting it to a string.

I think what @cvrebert meant in this comment was to consider the title and content as a string when you add them to the popover/tooltip not preemptively before the check. But that's not possible as the check is done before that.

The proper fix is to merge PR #20210 for the data-content of the popover and apply the same fix for the data-title in the tooltip (and add unit test that are not present in #20210)

@Johann-S
Copy link
Member Author

Moreover the data-title and data-content can be an element or a function and you are converting it to a string.

That's not true, I only convert when it's a number that's all.
Moreover same is already done for delay

@pvdlg
Copy link
Contributor

pvdlg commented Mar 30, 2017

The delay is not converted:

if (config.delay && typeof config.delay === 'number') {
    config.delay = {
        show : config.delay,
        hide : config.delay
     }
}

The delay can be an object with show/hide or a single number. This code handle the second case (a single number meaning both show and hide are the same). No conversion here and the original parameter still goes through Util.typeCheckConfig.

@Johann-S
Copy link
Member Author

For me it's a conversion but that's not the subject here.
Thank you for your feedbacks 👍

@pvdlg
Copy link
Contributor

pvdlg commented Mar 30, 2017

if config.delay is a string then config.delay.show will also be a string and will fail in Util.typeCheckConfig as intended. What I meant by 'not a conversion' is that is doesn't change the type. You code change the type by doing toString().

@Johann-S
Copy link
Member Author

At the beginning config.delay is a Number and at the end config.delay is an Object that's why I said it's a conversion.

@pvdlg
Copy link
Contributor

pvdlg commented Mar 30, 2017

Actually I think the code regarding the delay, should be done after the call to Util.typeCheckConfig otherwise it defeat the purpose of the check and let the user pass any type as the delay.
Basically we shouldn't change the config before checking it.

@Johann-S Johann-S changed the title Popover - fix error when content or title is a number Popover + Tooltip - fix error when content or title is a number Mar 31, 2017
@Johann-S
Copy link
Member Author

It's a point of view but, we only accept string, element and function for title and content so if it's not a string we convert the argument.

About delay to be compliant with documentation we have to perform the conversion.

Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type
If a number is supplied, delay is applied to both hide/show
Object structure is: delay: { "show": 500, "hide": 100 }

For me they are not a better point of view than an other, your point of view is equal to mine but a path have been chosen that's all.

@Johann-S Johann-S merged commit 5142de7 into v4-dev Mar 31, 2017
@Johann-S Johann-S deleted the v4-popover-content branch March 31, 2017 08:04
@mdo mdo mentioned this pull request Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants