mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
AK+Kernel: Avoid unescaped control chars in append_escaped_for_json()
Otherwise it could produce invalid JSON.
This commit is contained in:
parent
e1e91f6c85
commit
27e3589f61
2 changed files with 8 additions and 8 deletions
|
@ -148,9 +148,6 @@ void StringBuilder::append_escaped_for_json(StringView const& string)
|
|||
{
|
||||
for (auto ch : string) {
|
||||
switch (ch) {
|
||||
case '\e':
|
||||
append("\\u001B");
|
||||
break;
|
||||
case '\b':
|
||||
append("\\b");
|
||||
break;
|
||||
|
@ -167,7 +164,10 @@ void StringBuilder::append_escaped_for_json(StringView const& string)
|
|||
append("\\\\");
|
||||
break;
|
||||
default:
|
||||
append(ch);
|
||||
if (ch >= 0 && ch <= 0x1f)
|
||||
append(String::formatted("\\u{:04x}", ch));
|
||||
else
|
||||
append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue