1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:57:44 +00:00

LibJS: Trim all types of whitespace characters before parsing numbers

This commit is contained in:
Idan Horowitz 2022-02-19 22:47:05 +02:00 committed by Linus Groh
parent 232e830a0a
commit 60bc5e3b5b
3 changed files with 3 additions and 2 deletions

View file

@ -31,6 +31,7 @@
#include <LibJS/Runtime/ProxyObject.h>
#include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/StringObject.h>
#include <LibJS/Runtime/StringPrototype.h>
#include <LibJS/Runtime/SymbolObject.h>
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/Value.h>
@ -476,7 +477,7 @@ ThrowCompletionOr<Value> Value::to_number(GlobalObject& global_object) const
case Type::Double:
return *this;
case Type::String: {
auto string = as_string().string().trim_whitespace();
String string = Utf8View(as_string().string()).trim(whitespace_characters, AK::TrimMode::Both).as_string();
if (string.is_empty())
return Value(0);
if (string == "Infinity" || string == "+Infinity")