-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Description
The CSS spec states that a number is:
Number values are denoted by <number>, and represent real numbers, possibly with a fractional component.
When written literally, a number is either an integer, or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits; optionally, it can be concluded by the letter “e” or “E” followed by an integer indicating the base-ten exponent in scientific notation. It corresponds to the <number-token> production in the CSS Syntax Module [CSS-SYNTAX-3]. As with integers, the first character of a number may be immediately preceded by - or + to indicate the number’s sign.
The value represents a literal number with the value 0. Expressions that merely evaluate to a with the value 0 (for example, calc(0)) do not match ; only literal s do.
As such, color strings using numbers with a decimal fraction should be valid, but that's not what happens currently.
Steps to reproduce
- Load the library (using Codepen, a project, etc.):
import cs from "color-string" - Call the library with a decimal fraction:
cs.get.rgb("rgb(1, 2.0, 3)") - Note that a null value is returned
- Call the library without a decimal fraction:
cs.get.rgb("rgb(1, 2, 3)") - Note that an array is returned
Notes
- This issue stems from the fact that the rgba regex pattern used to parse the number values can't handle decimal fractions
- This might affect other color strings as well