Removed some special escapes from def_to_proto.c, to match C++ protos.

This was not a bug -- the previous behavior was correct.  However this
change brings our implementation-specific details in line with C++.

PiperOrigin-RevId: 511273853
pull/13171/head
Joshua Haberman 2 years ago committed by Copybara-Service
parent a7a097d443
commit 2d40e1e2ee
  1. 12
      upb/util/def_to_proto.c
  2. 15
      upb/util/def_to_proto_test.cc

@ -102,28 +102,20 @@ static bool upb_isprint(char ch) { return ch >= 0x20 && ch <= 0x7f; }
static int special_escape(char ch) { static int special_escape(char ch) {
switch (ch) { switch (ch) {
case '\a': // This is the same set of special escapes recognized by
return 'a'; // absl::CEscape().
case '\b':
return 'b';
case '\f':
return 'f';
case '\n': case '\n':
return 'n'; return 'n';
case '\r': case '\r':
return 'r'; return 'r';
case '\t': case '\t':
return 't'; return 't';
case '\v':
return 'v';
case '\\': case '\\':
return '\\'; return '\\';
case '\'': case '\'':
return '\''; return '\'';
case '"': case '"':
return '"'; return '"';
case '\?':
return '?';
default: default:
return -1; return -1;
} }

@ -301,4 +301,19 @@ TEST(FuzzTest, PackageStartsWithNumber) {
ParseTextProtoOrDie(R"pb(file { name: "" package: "0" })pb")); ParseTextProtoOrDie(R"pb(file { name: "" package: "0" })pb"));
} }
TEST(FuzzTest, RoundTripDescriptorRegression) {
RoundTripDescriptor(ParseTextProtoOrDie(R"pb(file {
name: ""
message_type {
name: "A"
field {
name: "B"
number: 1
type: TYPE_BYTES
default_value: "\007"
}
}
})pb"));
}
} // namespace upb_test } // namespace upb_test

Loading…
Cancel
Save