From 1dff9a7ce4e5fa5160c0ba7f16eddb892da6e325 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Fri, 4 Sep 2020 12:25:42 -0700 Subject: [PATCH] Don't crash when writing Infinity in JS mode (#1069) Closes #1031 --- CHANGELOG.md | 2 ++ lib/src/util/number.dart | 2 ++ test/output_test.dart | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e04806f4..667b4b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,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. diff --git a/lib/src/util/number.dart b/lib/src/util/number.dart index 02aaae43..da9679bc 100644 --- a/lib/src/util/number.dart +++ b/lib/src/util/number.dart @@ -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 diff --git a/test/output_test.dart b/test/output_test.dart index 582e59d6..8be030f7 100644 --- a/test/output_test.dart +++ b/test/output_test.dart @@ -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}; }"));