Skip to content
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

Don't crash when writing Infinity in JS mode #1069

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Improve some error messages for edge-case parse failures.

* Don't crash when writing `Infinity` in JS mode.

## 1.26.10

* Fixes a bug where two adjacent combinators could cause an error.
Expand Down
2 changes: 2 additions & 0 deletions lib/src/util/number.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ bool fuzzyGreaterThanOrEquals(num number1, num number2) =>

/// Returns whether [number] is [fuzzyEquals] to an integer.
bool fuzzyIsInt(num number) {
// Check this before is int to work around dart-lang/sdk#43325.
if (number.isInfinite || number.isNaN) return false;
if (number is int) return true;

// Check against 0.5 rather than 0.0 so that we catch numbers that are both
Expand Down
5 changes: 5 additions & 0 deletions test/output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void main() {
});

group("for floating-point numbers", () {
test("Infinity", () {
expect(compileString("a {b: 1e999}"),
equalsIgnoringWhitespace("a { b: Infinity; }"));
});

test(">= 1e21", () {
expect(compileString("a {b: 1.01e21}"),
equalsIgnoringWhitespace("a { b: 101${'0' * 19}; }"));
Expand Down