mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibJS: Make StringToNumber case sensitive when falling back to strtod
We use strtod to convert a string to number after checking whether the string is [+-]Infinity, however strtod also checks for either 'inf' or 'infinity' in a case-insensitive. There are still valid cases for strtod to return infinity like 10e100000 so we just check if the "number" contains 'i' or 'I' in which case the strtod infinity is not valid.
This commit is contained in:
parent
9d05ca7b20
commit
0f9434a02c
2 changed files with 19 additions and 0 deletions
|
@ -500,6 +500,11 @@ ThrowCompletionOr<Value> Value::to_number(GlobalObject& global_object) const
|
|||
auto parsed_double = strtod(string.characters(), &endptr);
|
||||
if (*endptr)
|
||||
return js_nan();
|
||||
// NOTE: Per the spec only exactly [+-]Infinity should result in infinity
|
||||
// but strtod gives infinity for any case-insensitive 'infinity' or 'inf' string.
|
||||
if (isinf(parsed_double) && string.contains('i', AK::CaseSensitivity::CaseInsensitive))
|
||||
return js_nan();
|
||||
|
||||
return Value(parsed_double);
|
||||
}
|
||||
case SYMBOL_TAG:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue