From f457ea95f82729e7e27f626a469d37ab22b384de Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Sat, 18 Feb 2023 22:29:47 +0000 Subject: [PATCH] Fix string to number conversion for `infinity` (#2607) This Pull Request changes the following: - Fix string to number conversion for all invalid variants of `infinity` --- boa_engine/src/string/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/boa_engine/src/string/mod.rs b/boa_engine/src/string/mod.rs index e517d0fdd9..1e365a5b99 100644 --- a/boa_engine/src/string/mod.rs +++ b/boa_engine/src/string/mod.rs @@ -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, }; @@ -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 )`