From 2d40e1e2ee8902839ad534e6ebb9c15657906d2e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 21 Feb 2023 12:27:15 -0800 Subject: [PATCH] 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 --- upb/util/def_to_proto.c | 12 ++---------- upb/util/def_to_proto_test.cc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/upb/util/def_to_proto.c b/upb/util/def_to_proto.c index 8513206edf..2067bb5b3a 100644 --- a/upb/util/def_to_proto.c +++ b/upb/util/def_to_proto.c @@ -102,28 +102,20 @@ static bool upb_isprint(char ch) { return ch >= 0x20 && ch <= 0x7f; } static int special_escape(char ch) { switch (ch) { - case '\a': - return 'a'; - case '\b': - return 'b'; - case '\f': - return 'f'; + // This is the same set of special escapes recognized by + // absl::CEscape(). case '\n': return 'n'; case '\r': return 'r'; case '\t': return 't'; - case '\v': - return 'v'; case '\\': return '\\'; case '\'': return '\''; case '"': return '"'; - case '\?': - return '?'; default: return -1; } diff --git a/upb/util/def_to_proto_test.cc b/upb/util/def_to_proto_test.cc index 2b3f5e75f2..1fa88a72ae 100644 --- a/upb/util/def_to_proto_test.cc +++ b/upb/util/def_to_proto_test.cc @@ -301,4 +301,19 @@ TEST(FuzzTest, PackageStartsWithNumber) { 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