summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-04 18:04:10 +0100
committerLinus Groh <mail@linusgroh.de>2022-10-04 20:05:09 +0100
commitd2e9faf2da9be8d92d5f5d5010ae19bad4b74af9 (patch)
tree23d35f3242501af660f9bdee9eb2bac0013eaeba /Userland
parent0db55693a99e11639723f17e623ed605cda38457 (diff)
downloadserenity-d2e9faf2da9be8d92d5f5d5010ae19bad4b74af9.zip
LibWeb: Run 'UTF-8 decode' in parse_json_bytes_to_javascript_value()
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Infra/JSON.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Infra/JSON.cpp b/Userland/Libraries/LibWeb/Infra/JSON.cpp
index 943fd384f2..34001d2f08 100644
--- a/Userland/Libraries/LibWeb/Infra/JSON.cpp
+++ b/Userland/Libraries/LibWeb/Infra/JSON.cpp
@@ -6,6 +6,7 @@
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Value.h>
+#include <LibTextCodec/Decoder.h>
#include <LibWeb/Infra/JSON.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -23,8 +24,9 @@ WebIDL::ExceptionOr<JS::Value> parse_json_string_to_javascript_value(JS::VM& vm,
// https://infra.spec.whatwg.org/#parse-json-bytes-to-a-javascript-value
WebIDL::ExceptionOr<JS::Value> parse_json_bytes_to_javascript_value(JS::VM& vm, ReadonlyBytes bytes)
{
- // 1. Let string be the result of running UTF-8 decode on bytes. [ENCODING]
- auto string = StringView { bytes };
+ // 1. Let string be the result of running UTF-8 decode on bytes.
+ TextCodec::UTF8Decoder decoder;
+ auto string = decoder.to_utf8(bytes);
// 2. Return the result of parsing a JSON string to an Infra value given string.
return parse_json_string_to_javascript_value(vm, string);
@@ -57,7 +59,8 @@ WebIDL::ExceptionOr<ByteBuffer> serialize_javascript_value_to_json_bytes(JS::VM&
// 1. Let string be the result of serializing a JavaScript value to a JSON string given value.
auto string = TRY(serialize_javascript_value_to_json_string(vm, value));
- // 2. Return the result of running UTF-8 encode on string. [ENCODING]
+ // 2. Return the result of running UTF-8 encode on string.
+ // NOTE: LibJS strings are stored as UTF-8.
return TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(string.bytes()));
}