Commit ec9e6e05 authored by Kenton Varda's avatar Kenton Varda

Support decoding unicode escapes in JSON strings.

parent b40445e7
...@@ -282,6 +282,9 @@ KJ_TEST("decode all types") { ...@@ -282,6 +282,9 @@ KJ_TEST("decode all types") {
CASE(R"({"structField":{"boolField":true}})", root.getStructField().getBoolField() == true); CASE(R"({"structField":{"boolField":true}})", root.getStructField().getBoolField() == true);
CASE(R"({"enumField":"bar"})", root.getEnumField() == TestEnum::BAR); CASE(R"({"enumField":"bar"})", root.getEnumField() == TestEnum::BAR);
CASE_NO_ROUNDTRIP(R"({"textField":"foo\u1234bar"})",
kj::str("foo\u1234bar") == root.getTextField());
CASE_THROW_RECOVERABLE(R"({"structField":null})", "Expected object value"); CASE_THROW_RECOVERABLE(R"({"structField":null})", "Expected object value");
CASE_THROW_RECOVERABLE(R"({"structList":null})", "Expected list value"); CASE_THROW_RECOVERABLE(R"({"structList":null})", "Expected list value");
CASE_THROW_RECOVERABLE(R"({"boolList":null})", "Expected list value"); CASE_THROW_RECOVERABLE(R"({"boolList":null})", "Expected list value");
......
...@@ -828,9 +828,13 @@ private: ...@@ -828,9 +828,13 @@ private:
} }
} }
// TODO(soon): Support at least basic multi-lingual plane, ie ignore surrogates. if (codePoint < 128) {
KJ_REQUIRE(codePoint < 128, "non-ASCII unicode escapes are not supported (yet!)"); target.add(0x7f & static_cast<char>(codePoint));
target.add(0x7f & static_cast<char>(codePoint)); } else {
// TODO(perf): This is sorta malloc-heavy...
char16_t u = codePoint;
target.addAll(kj::decodeUtf16(kj::arrayPtr(&u, 1)));
}
} }
const size_t maxNestingDepth; const size_t maxNestingDepth;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment