summaryrefslogtreecommitdiff
path: root/AK/JsonParser.cpp
diff options
context:
space:
mode:
authorLepkoQQ <lepko.san@gmail.com>2020-06-19 23:46:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-20 17:04:03 +0200
commitb1c99c189160972d7d52ebd482a4c1d7267b1c1f (patch)
treebc84d42eaec07c8be17fb99fc07621583d032c01 /AK/JsonParser.cpp
parent64513f3c23f880b87d26e669b777b4796b065796 (diff)
downloadserenity-b1c99c189160972d7d52ebd482a4c1d7267b1c1f.zip
AK: Fix JsonParser double encoding multibyte utf-8 chararcters
Diffstat (limited to 'AK/JsonParser.cpp')
-rw-r--r--AK/JsonParser.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp
index 578b84741c..5697287ef6 100644
--- a/AK/JsonParser.cpp
+++ b/AK/JsonParser.cpp
@@ -72,7 +72,7 @@ String JsonParser::consume_quoted_string()
{
if (!consume_specific('"'))
return {};
- Vector<u32, 1024> buffer;
+ StringBuilder final_sb;
for (;;) {
size_t peek_index = m_index;
@@ -88,8 +88,7 @@ String JsonParser::consume_quoted_string()
if (peek_index != m_index) {
while (peek_index != m_index) {
- u32 value = m_input.characters_without_null_termination()[m_index];
- buffer.append(value);
+ final_sb.append(m_input.characters_without_null_termination()[m_index]);
m_index++;
}
}
@@ -99,26 +98,26 @@ String JsonParser::consume_quoted_string()
if (ch == '"')
break;
if (ch != '\\') {
- buffer.append(consume());
+ final_sb.append(consume());
continue;
}
consume();
char escaped_ch = consume();
switch (escaped_ch) {
case 'n':
- buffer.append('\n');
+ final_sb.append('\n');
break;
case 'r':
- buffer.append('\r');
+ final_sb.append('\r');
break;
case 't':
- buffer.append('\t');
+ final_sb.append('\t');
break;
case 'b':
- buffer.append('\b');
+ final_sb.append('\b');
break;
case 'f':
- buffer.append('\f');
+ final_sb.append('\f');
break;
case 'u': {
StringBuilder sb;
@@ -129,27 +128,19 @@ String JsonParser::consume_quoted_string()
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
if (codepoint.has_value()) {
- buffer.append(codepoint.value());
+ final_sb.append_codepoint(codepoint.value());
} else {
- buffer.append('?');
+ final_sb.append('?');
}
} break;
default:
- buffer.append(escaped_ch);
+ final_sb.append(escaped_ch);
break;
}
}
if (!consume_specific('"'))
return {};
- if (buffer.is_empty())
- return String::empty();
-
- StringBuilder final_sb;
- for (auto cp : buffer) {
- final_sb.append_codepoint(cp);
- }
-
return final_sb.to_string();
}