TextFormat should always escape ASCII 127 (DEL).

This was missed in the previous CL. DEL characters would be printed unescaped, which makes them more difficult to read but should still be data-preserving.

PiperOrigin-RevId: 592946127
pull/15173/head
Joshua Haberman 1 year ago committed by Copybara-Service
parent e27855032a
commit a9bb9c5181
  1. 11
      src/google/protobuf/text_format.cc

@ -1654,13 +1654,22 @@ namespace {
// Returns true if `ch` needs to be escaped in TextFormat, independent of any
// UTF-8 validity issues.
bool DefinitelyNeedsEscape(unsigned char ch) {
if (ch < 32) return true;
if (ch >= 0x80) {
return false; // High byte; no escapes necessary if UTF-8 is vaid.
}
if (!absl::ascii_isprint(ch)) {
return true; // Unprintable characters need escape.
}
switch (ch) {
case '\"':
case '\'':
case '\\':
// These characters need escapes despite being printable.
return true;
}
return false;
}

Loading…
Cancel
Save