mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +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: https://github.com/SerenityOS/serenity/commit/c54855682c3 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);
|
||||
}
|
||||
|
||||
void add(const StringView& key, double value)
|
||||
{
|
||||
begin_item(key);
|
||||
m_builder.appendf("%f", value);
|
||||
}
|
||||
|
||||
JsonArraySerializer<Builder> add_array(const StringView& key)
|
||||
{
|
||||
begin_item(key);
|
||||
|
|
|
@ -100,9 +100,11 @@ String JsonParser::consume_quoted_string()
|
|||
char escaped_ch = consume();
|
||||
switch (escaped_ch) {
|
||||
case 'n':
|
||||
case 'r':
|
||||
buffer.append('\n');
|
||||
break;
|
||||
case 'r':
|
||||
buffer.append('\r');
|
||||
break;
|
||||
case 't':
|
||||
buffer.append('\t');
|
||||
break;
|
||||
|
@ -225,6 +227,7 @@ JsonValue JsonParser::parse_number()
|
|||
ASSERT(ok);
|
||||
|
||||
int fraction = fraction_string.to_uint(ok);
|
||||
fraction *= (whole < 0) ? -1 : 1;
|
||||
ASSERT(ok);
|
||||
|
||||
auto divider = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue