[JsonWriter] Do not break in EscapeString when encountering a null byte (#33127)

Instead just Utf-16 encode the null byte when dumping the value to a
string form.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/33139/head
Yijie Ma 2 years ago committed by GitHub
parent 87a0eb46be
commit 3526defc19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/lib/json/json_writer.cc
  2. 1
      test/core/json/corpus/testcase-6037245441474560
  3. 1
      test/core/json/corpus/testcase-6329722588758016

@ -145,9 +145,7 @@ void JsonWriter::EscapeString(const std::string& string) {
OutputChar('"');
for (size_t idx = 0; idx < string.size(); ++idx) {
uint8_t c = static_cast<uint8_t>(string[idx]);
if (c == 0) {
break;
} else if (c >= 32 && c <= 126) {
if (c >= 32 && c <= 126) {
if (c == '\\' || c == '"') OutputChar('\\');
OutputChar(static_cast<char>(c));
} else if (c < 32 || c == 127) {

@ -0,0 +1 @@
"\u0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Loading…
Cancel
Save