-
Notifications
You must be signed in to change notification settings - Fork 125
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
Parsing z-index values outside of int range throws an OverflowException #158
Comments
I'm also encountering this, it's in a rather large 3rd party css file that I don't have direct control over. I'm seeing z-index values of 999999999999999. I can work-around by replacing those with smaller numbers before parsing, but it would be nice if the library tolerated this. |
It's an interesting issue since CSS doesn't allow the value, but browsers handle the incorrect syntax. I'm looking at options on how to handle it since, technically, one could overflow an int64 value as well, but it's never fractional. |
I haven't peeked at your code yet, but something like "if length >= 10 and first character > 2". to speed it up maybe a TryParse and only check that on failure? |
The most recent version fixes the parsing by first trying to parse the value as an integer (as it did before). If that fails, the string representing the numeric value is scanned to check that all characters are digits. If so, the value is set to int.MaxValue. While not ideal, it does allow the parser to continue without exception. Any non-digit characters will throw an explicit exception. This introduces an edge case where the value is negative and smaller than in.MinValue. That scenario isn't currently handled, but as an edge case should not affect standard parsing behavior. |
that sounds great! |
For example, any z-index values greater than INT_MAX throws, such as this:
Would also apply to values smaller than INT_MIN.
Stack trace
The standard doesn't actually limit z-index values to any particular range, though realistically speaking every browser clamps them to Int32.
The text was updated successfully, but these errors were encountered: