mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 17:24:48 -05:00
AK: Identify negative zero when parsing Json and represent with a double
Regardless of the backing type that the number would otherwise parse to, if it is zero and the sign was supposed to be negative then it needs to be a floating point number to represent the correct value.
This commit is contained in:
parent
7bea0d501e
commit
1d95fd5443
Notes:
sideshowbarker
2024-07-17 20:37:22 +09:00
Author: https://github.com/ForLoveOfCats Commit: https://github.com/SerenityOS/serenity/commit/1d95fd54433 Pull-request: https://github.com/SerenityOS/serenity/pull/12004 Reviewed-by: https://github.com/linusg ✅
1 changed files with 8 additions and 0 deletions
|
@ -191,6 +191,7 @@ ErrorOr<JsonValue> JsonParser::parse_number()
|
|||
Vector<char, 128> fraction_buffer;
|
||||
|
||||
bool is_double = false;
|
||||
bool all_zero = true;
|
||||
for (;;) {
|
||||
char ch = peek();
|
||||
if (ch == '.') {
|
||||
|
@ -202,6 +203,9 @@ ErrorOr<JsonValue> JsonParser::parse_number()
|
|||
continue;
|
||||
}
|
||||
if (ch == '-' || (ch >= '0' && ch <= '9')) {
|
||||
if (ch != '-' && ch != '0')
|
||||
all_zero = false;
|
||||
|
||||
if (is_double) {
|
||||
if (ch == '-')
|
||||
return Error::from_string_literal("JsonParser: Error while parsing number"sv);
|
||||
|
@ -229,6 +233,10 @@ ErrorOr<JsonValue> JsonParser::parse_number()
|
|||
StringView number_string(number_buffer.data(), number_buffer.size());
|
||||
|
||||
#ifndef KERNEL
|
||||
// Check for negative zero which needs to be forced to be represented with a double
|
||||
if (number_string.starts_with('-') && all_zero)
|
||||
return JsonValue(-0.0);
|
||||
|
||||
if (is_double) {
|
||||
// FIXME: This logic looks shaky.
|
||||
int whole = 0;
|
||||
|
|
Loading…
Reference in a new issue