Skip to content

Commit

Permalink
Fix string to number conversion for infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Feb 18, 2023
1 parent 60c25b4 commit 3125ad3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions boa_engine/src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ impl JsString {
(Some(b'0'), Some(b'b' | b'B')) => Some(2),
(Some(b'0'), Some(b'o' | b'O')) => Some(8),
(Some(b'0'), Some(b'x' | b'X')) => Some(16),
// Make sure that no further variants of "infinity" are parsed.
(Some(b'i' | b'I'), _) => {
return f64::NAN;
}
_ => None,
};

Expand Down Expand Up @@ -430,11 +434,7 @@ impl JsString {
return value;
}

match string {
// Handle special cases so `fast_float` does not return infinity.
"inf" | "+inf" | "-inf" => f64::NAN,
string => fast_float::parse(string).unwrap_or(f64::NAN),
}
fast_float::parse(string).unwrap_or(f64::NAN)
}

/// Abstract operation `StringToBigInt ( str )`
Expand Down

0 comments on commit 3125ad3

Please sign in to comment.