From 37dfe806f84617390e9779fc237a0a77f5a50d6d Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 28 Apr 2023 10:11:27 -0700 Subject: [PATCH] Added a conformance test for embedded nulls in JSON strings. Going forward we will be forbidding `null` in `json_name`, but we will continue to support embedded `null` in JSON value. This conformance test will help clarify that this is a supported use case. PiperOrigin-RevId: 527918031 --- conformance/binary_json_conformance_suite.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 21b659297dd0..745a40061361 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -2378,7 +2378,7 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { // String fields. RunValidJsonTest("StringField", REQUIRED, R"({"optionalString": "Hello world!"})", - "optional_string: \"Hello world!\""); + R"(optional_string: "Hello world!")"); RunValidJsonTest("StringFieldUnicode", REQUIRED, // Google in Chinese. R"({"optionalString": "谷歌"})", @@ -2397,6 +2397,9 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { // The character is an emoji: grinning face with smiling eyes. 😁 R"({"optionalString": "\uD83D\uDE01"})", R"(optional_string: "\xF0\x9F\x98\x81")"); + RunValidJsonTest("StringFieldEmbeddedNull", REQUIRED, + R"({"optionalString": "Hello\u0000world!"})", + R"(optional_string: "Hello\000world!")"); // Unicode escapes must start with "\u" (lowercase u). ExpectParseFailureForJson("StringFieldUppercaseEscapeLetter", RECOMMENDED,