mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
AK: A few JSON improvements
* Add double number to object serializer * Handle negative double numbers correctly * Handle \r and \n in quoted strings independently This improves the situation when keys contain \r or \n that currently has the effect that "a\rkey" and "a\nkey" in an JSON object are the same key value.
This commit is contained in:
parent
c925aaceb2
commit
c54855682c
Notes:
sideshowbarker
2024-07-19 08:01:46 +09:00
Author: https://github.com/lnzero1dev
Commit: c54855682c
Pull-request: https://github.com/SerenityOS/serenity/pull/1550
2 changed files with 10 additions and 1 deletions
|
@ -109,6 +109,12 @@ public:
|
||||||
m_builder.appendf("%llu", value);
|
m_builder.appendf("%llu", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add(const StringView& key, double value)
|
||||||
|
{
|
||||||
|
begin_item(key);
|
||||||
|
m_builder.appendf("%f", value);
|
||||||
|
}
|
||||||
|
|
||||||
JsonArraySerializer<Builder> add_array(const StringView& key)
|
JsonArraySerializer<Builder> add_array(const StringView& key)
|
||||||
{
|
{
|
||||||
begin_item(key);
|
begin_item(key);
|
||||||
|
|
|
@ -100,9 +100,11 @@ String JsonParser::consume_quoted_string()
|
||||||
char escaped_ch = consume();
|
char escaped_ch = consume();
|
||||||
switch (escaped_ch) {
|
switch (escaped_ch) {
|
||||||
case 'n':
|
case 'n':
|
||||||
case 'r':
|
|
||||||
buffer.append('\n');
|
buffer.append('\n');
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
buffer.append('\r');
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
buffer.append('\t');
|
buffer.append('\t');
|
||||||
break;
|
break;
|
||||||
|
@ -225,6 +227,7 @@ JsonValue JsonParser::parse_number()
|
||||||
ASSERT(ok);
|
ASSERT(ok);
|
||||||
|
|
||||||
int fraction = fraction_string.to_uint(ok);
|
int fraction = fraction_string.to_uint(ok);
|
||||||
|
fraction *= (whole < 0) ? -1 : 1;
|
||||||
ASSERT(ok);
|
ASSERT(ok);
|
||||||
|
|
||||||
auto divider = 1;
|
auto divider = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue