Skip to content

Commit

Permalink
TextFormat should always escape ASCII 127 (DEL).
Browse files Browse the repository at this point in the history
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
  • Loading branch information
haberman authored and copybara-github committed Dec 21, 2023
1 parent e278550 commit a9bb9c5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/google/protobuf/text_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a9bb9c5

Please sign in to comment.