mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +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:
parent
ee21a724c7
commit
5e164052f6
7 changed files with 68 additions and 33 deletions
|
@ -144,4 +144,32 @@ void StringBuilder::append(const Utf32View& utf32_view)
|
|||
}
|
||||
}
|
||||
|
||||
void StringBuilder::append_escaped_for_json(const StringView& string)
|
||||
{
|
||||
for (auto ch : string) {
|
||||
switch (ch) {
|
||||
case '\e':
|
||||
append("\\u001B");
|
||||
break;
|
||||
case '\b':
|
||||
append("\\b");
|
||||
break;
|
||||
case '\n':
|
||||
append("\\n");
|
||||
break;
|
||||
case '\t':
|
||||
append("\\t");
|
||||
break;
|
||||
case '\"':
|
||||
append("\\\"");
|
||||
break;
|
||||
case '\\':
|
||||
append("\\\\");
|
||||
break;
|
||||
default:
|
||||
append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue