Skip to content

Commit

Permalink
Don't crash when using Infinity or NaN as a key in a map (#1073)
Browse files Browse the repository at this point in the history
Closes #3126
  • Loading branch information
nex3 committed Oct 27, 2020
1 parent c4f95d4 commit 300197c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,8 @@
* **Potentially breaking bug fix:** `meta.load-css()` now correctly uses the
name `$url` for its first argument, rather than `$module`.

* Don't crash when using `Infinity` or `NaN` as a key in a map.

* Emit a proper parse error for a `=` with no right-hand side in a function.

## 1.27.0
Expand Down
4 changes: 3 additions & 1 deletion lib/src/util/number.dart
Expand Up @@ -19,7 +19,9 @@ bool fuzzyEquals(num number1, num number2) =>
final _inverseEpsilon = 1 / epsilon;

/// Returns a hash code for [number] that matches [fuzzyEquals].
int fuzzyHashCode(num number) => (number * _inverseEpsilon).round().hashCode;
int fuzzyHashCode(num number) => number.isInfinite || number.isNaN
? number.hashCode
: (number * _inverseEpsilon).round().hashCode;

/// Returns whether [number1] is less than [number2], and not [fuzzyEquals].
bool fuzzyLessThan(num number1, num number2) =>
Expand Down

0 comments on commit 300197c

Please sign in to comment.