You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid parsing to non-finite floating point numbers #167
In #165, this input 3E833 is parsed as a Token::Number whose value is std::f32::INFINITY, which serializes as inf.
We should definitely not serialize any number as inf (maybe an arbitrary large number instead), but probably also avoid non-finite numbers in tokens in the first place.
I guess the question is, should encountering a non-finite number just yield an UnexpectedToken error? I don't know the details of the CSS spec well enough :)
CSS theoretically supports infinite precision and infinite ranges for all value types; however in reality implementations have finite capacity. UAs should support reasonably useful ranges and precisions.
Unfortunately I couldn’t easily find spec text that says what to do with inputs that exceed that chosen capacity.
I think we should parse it, and clamp it to some appropriate range. We should probably just not serialize inf. Gecko doesn't serialize inf, maybe this bug was fixed?
Activity
federicomenaquintero commentedon Dec 5, 2019
FWIW, in librsvg I ended up with this:
Of course this is tied to librsvg's error enums. The code uses
expect_finite_numbereverywhere instead of cssparser's stockexpect_number.federicomenaquintero commentedon Dec 5, 2019
I guess the question is, should encountering a non-finite number just yield an UnexpectedToken error? I don't know the details of the CSS spec well enough :)
SimonSapin commentedon Dec 5, 2019
https://drafts.csswg.org/css-values/#numeric-ranges
Unfortunately I couldn’t easily find spec text that says what to do with inputs that exceed that chosen capacity.
emilio commentedon Dec 5, 2019
I think we should parse it, and clamp it to some appropriate range. We should probably just not serialize
inf. Gecko doesn't serializeinf, maybe this bug was fixed?SimonSapin commentedon Dec 5, 2019
Probably when we started using the
dtoacrate:Playground, output:
federicomenaquintero commentedon Dec 5, 2019
Section 5.1 says:
So, "too large" -> "parse error" sounds reasonable.
But section 10.9 has an interesting note:
So clamping to $large_value sounds fine too! If that makes number values rountrippable, this sounds good.
SimonSapin commentedon Dec 6, 2019
Parse errors seems like it might not be web-compatible at least for
z-indexwhere some pages use ever-larger value