mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +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
Notes:
sideshowbarker
2024-07-18 04:03:39 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/27e3589f611 Pull-request: https://github.com/SerenityOS/serenity/pull/9976
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,9 +101,6 @@ KResult KBufferBuilder::append_escaped_for_json(const StringView& string)
|
|||
{
|
||||
for (auto ch : string) {
|
||||
switch (ch) {
|
||||
case '\e':
|
||||
TRY(append("\\u001B"));
|
||||
break;
|
||||
case '\b':
|
||||
TRY(append("\\b"));
|
||||
break;
|
||||
|
@ -120,7 +117,10 @@ KResult KBufferBuilder::append_escaped_for_json(const StringView& string)
|
|||
TRY(append("\\\\"));
|
||||
break;
|
||||
default:
|
||||
TRY(append(ch));
|
||||
if (ch >= 0 && ch <= 0x1f)
|
||||
TRY(append(String::formatted("\\u{:04x}", ch)));
|
||||
else
|
||||
TRY(append(ch));
|
||||
}
|
||||
}
|
||||
return KSuccess;
|
||||
|
|
Loading…
Reference in a new issue