-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix minor TimingFunction validation issue #8910
Fix minor TimingFunction validation issue #8910
Conversation
} | ||
|
||
var val = parseFloat(str, 10), | ||
isNum = (typeof (val) === "number") && !isNaN(val) && | ||
isNum = (typeof val === "number") && !isNaN(val) && | ||
(val !== Infinity) && (val !== -Infinity); |
There was a problem hiding this comment.
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?
Code review complete. I think this can be solved without a new regex. |
@redmunds Your solution works well, therefore I used it. |
@@ -215,6 +215,9 @@ define(function (require, exports, module) { | |||
it("should correct cubic-bezier function with 5 parameters", function () { | |||
testInvalidBezier("cubic-bezier(0, 0, 1, 1, 1)", ["cubic-bezier(0, 0, 1, 1)", "0", "0", "1", "1"]); | |||
}); | |||
it("should correct cubic-bezier function with trailing comma", function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay! Unit test!
Good catch. Merging. |
…eption Fix minor TimingFunction validation issue
This fixes a rather uncommon issue in TimingFunction validation. Steps:
animation-timing-function: cubic-bezier(0, 0, 0, 0,)
(notice the trailing comma)Result: Console error, no inline editor
Expected: Inline editor should auto-correct the invalid function