Automated rollback of commit 112fa94402.

PiperOrigin-RevId: 502941218
pull/11581/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 6a0bd183ee
commit 29331cbd4c
  1. 13
      src/google/protobuf/json/internal/parser.cc
  2. 10
      src/google/protobuf/json/json_test.cc

@ -1181,6 +1181,19 @@ absl::Status ParseField(JsonLexer& lex, const Desc<Traits>& desc,
if (absl::StartsWith(name, "[") && absl::EndsWith(name, "]")) { if (absl::StartsWith(name, "[") && absl::EndsWith(name, "]")) {
absl::string_view extn_name = name.substr(1, name.size() - 2); absl::string_view extn_name = name.substr(1, name.size() - 2);
field = Traits::ExtensionByName(desc, extn_name); field = Traits::ExtensionByName(desc, extn_name);
if (field.has_value()) {
// The check for whether this is an invalid field occurs below, since it
// is combined for both extension and non-extension fields.
auto correct_type_name = Traits::TypeName(desc);
if (Traits::TypeName(Traits::ContainingType(*field)) !=
correct_type_name) {
return lex.Invalid(absl::StrFormat(
"'%s' is a known extension name, but is not an extenion "
"of '%s' as expected",
extn_name, correct_type_name));
}
}
} else { } else {
field = Traits::FieldByName(desc, name); field = Traits::FieldByName(desc, name);
} }

@ -1053,6 +1053,16 @@ TEST_P(JsonTest, Extensions) {
R"("[protobuf_unittest.TestMixedFieldsAndExtensions.c]":42,)" R"("[protobuf_unittest.TestMixedFieldsAndExtensions.c]":42,)"
R"("b":[1,2,3],)" R"("b":[1,2,3],)"
R"("[protobuf_unittest.TestMixedFieldsAndExtensions.d]":[1,1,2,3,5,8,13]})")); R"("[protobuf_unittest.TestMixedFieldsAndExtensions.d]":[1,1,2,3,5,8,13]})"));
auto m2 = ToProto<protobuf_unittest::TestAllTypes>(R"json({
"[this.extension.does.not.exist]": 42
})json");
EXPECT_THAT(m2, StatusIs(absl::StatusCode::kInvalidArgument));
auto m3 = ToProto<protobuf_unittest::TestAllTypes>(R"json({
"[protobuf_unittest.TestMixedFieldsAndExtensions.c]": 42
})json");
EXPECT_THAT(m3, StatusIs(absl::StatusCode::kInvalidArgument));
} }
// Parsing does NOT work like MergeFrom: existing repeated field values are // Parsing does NOT work like MergeFrom: existing repeated field values are

Loading…
Cancel
Save