From 3125ad371d2b635d04e6726d54d00f93702bc6c3 Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Sat, 18 Feb 2023 22:34:37 +0100 Subject: [PATCH] Fix string to number conversion for `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 e517d0fdd9b..1e365a5b99f 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 )`