1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

AK+Kernel: Escape JSON keys & values

Grab the escaping logic from JSON string value serialization and use
it for serializing all keys and values.

Fixes #3917.
This commit is contained in:
Andreas Kling 2020-11-02 12:56:36 +01:00
parent ee21a724c7
commit 5e164052f6
7 changed files with 68 additions and 33 deletions

View file

@ -158,33 +158,8 @@ inline void JsonValue::serialize(Builder& builder) const
{
switch (m_type) {
case Type::String: {
auto size = m_value.as_string->length();
builder.append("\"");
for (size_t i = 0; i < size; i++) {
char ch = m_value.as_string->characters()[i];
switch (ch) {
case '\e':
builder.append("\\u001B");
break;
case '\b':
builder.append("\\b");
break;
case '\n':
builder.append("\\n");
break;
case '\t':
builder.append("\\t");
break;
case '\"':
builder.append("\\\"");
break;
case '\\':
builder.append("\\\\");
break;
default:
builder.append(ch);
}
}
builder.append_escaped_for_json({ m_value.as_string->characters(), m_value.as_string->length() });
builder.append("\"");
} break;
case Type::Array: