Automated rollback of commit 57d5ede3ec.

PiperOrigin-RevId: 526130253
pull/12526/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent d6ecec884c
commit 81106b10dc
  1. 9
      src/google/protobuf/descriptor.cc
  2. 8
      src/google/protobuf/descriptor_unittest.cc

@ -5927,8 +5927,13 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
case FieldDescriptor::CPPTYPE_STRING:
if (result->type() == FieldDescriptor::TYPE_BYTES) {
std::string value;
absl::CUnescape(proto.default_value(), &value);
result->default_value_string_ = alloc.AllocateStrings(value);
if (absl::CUnescape(proto.default_value(), &value)) {
result->default_value_string_ = alloc.AllocateStrings(value);
} else {
AddError(result->full_name(), proto,
DescriptorPool::ErrorCollector::DEFAULT_VALUE,
"Invalid escaping in default value.");
}
} else {
result->default_value_string_ =
alloc.AllocateStrings(proto.default_value());

@ -4548,6 +4548,12 @@ TEST_F(ValidationErrorTest, InvalidDefaults) {
" field { name: \"corge\" number: 6 label: LABEL_REPEATED type: "
"TYPE_INT32"
" default_value: \"1\" }"
// Invalid CEscaped bytes default.
" field { name: \"bytes_default\" number: 7 label: LABEL_OPTIONAL "
" type: TYPE_BYTES"
" default_value: \"\\\\\" }"
"}",
"foo.proto: Foo.foo: DEFAULT_VALUE: Couldn't parse default value "
@ -4558,6 +4564,8 @@ TEST_F(ValidationErrorTest, InvalidDefaults) {
"foo.proto: Foo.moo: DEFAULT_VALUE: Messages can't have default values.\n"
"foo.proto: Foo.corge: DEFAULT_VALUE: Repeated fields can't have default "
"values.\n"
"foo.proto: Foo.bytes_default: DEFAULT_VALUE: Invalid escaping in "
"default value.\n"
// This ends up being reported later because the error is detected at
// cross-linking time.
"foo.proto: Foo.mooo: DEFAULT_VALUE: Messages can't have default "

Loading…
Cancel
Save