Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fix minor TimingFunction validation issue #8910

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ define(function (require, exports, module) {
* If string is a number, then convert it.
*
* @param {string} str value parsed from page.
* @return { isNumber: boolean, value: number }
* @return { isNumber: boolean, value: ?number }
*/
function _convertToNumber(str) {
if (typeof (str) !== "string") {
return { isNumber: false };
if (typeof str !== "string" || /[^\d\s.\-]/.test(str)) {
return { isNumber: false, value: null };
}

var val = parseFloat(str, 10),
isNum = (typeof (val) === "number") && !isNaN(val) &&
isNum = (typeof val === "number") && !isNaN(val) &&
(val !== Infinity) && (val !== -Infinity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelgerber This is an interesting case. Due to the regex used to parse the cubic-bezier string, the last value is "everything past the 3rd comma and past whitespace". So there could be a lot of weird stuff in here -- too much I think to try to parse with our own regex.

So, I looked at the code that currently traps the exception and it's using the unary operator to convert from string to number. I think we still need parseFloat to make sure it's a base 10 number, but this code seems to be simpler, solve the problem, and all unit tests still work:

        if (typeof str !== "string") {
            return { isNumber: false, value: null };
        }

        var val = parseFloat(+str, 10),
            isNum = (typeof val === "number") && !isNaN(val) &&
                    (val !== Infinity) && (val !== -Infinity);

What do you think of this solution?


return {
Expand Down