From ae68344a883c08400e9f811bd15195b8d0f14abf Mon Sep 17 00:00:00 2001 From: cherylEnkidu <96084918+cherylEnkidu@users.noreply.github.com> Date: Thu, 25 Jan 2024 08:34:20 -0500 Subject: [PATCH] Support empty map in Firestore bundle (#12312) --- Firestore/core/src/bundle/bundle_serializer.cc | 10 ++++++++-- Firestore/core/test/unit/bundle/bundle_reader_test.cc | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Firestore/core/src/bundle/bundle_serializer.cc b/Firestore/core/src/bundle/bundle_serializer.cc index 9cc6f8e7b55..86942236791 100644 --- a/Firestore/core/src/bundle/bundle_serializer.cc +++ b/Firestore/core/src/bundle/bundle_serializer.cc @@ -584,10 +584,16 @@ Message BundleSerializer::DecodeValue( Message BundleSerializer::DecodeMapValue( JsonReader& reader, const json& map_json) const { - if (!map_json.is_object() || !map_json.contains("fields")) { - reader.Fail("mapValue is not a valid map"); + if (!map_json.is_object()) { + reader.Fail("mapValue is not a valid object"); return {}; } + + // Empty map doesn't have `fields` field. + if (!map_json.contains("fields")) { + return {}; + } + const auto& fields = map_json.at("fields"); if (!fields.is_object()) { reader.Fail("mapValue's 'field' is not a valid map"); diff --git a/Firestore/core/test/unit/bundle/bundle_reader_test.cc b/Firestore/core/test/unit/bundle/bundle_reader_test.cc index 54ddfc9f1d9..61b3f744845 100644 --- a/Firestore/core/test/unit/bundle/bundle_reader_test.cc +++ b/Firestore/core/test/unit/bundle/bundle_reader_test.cc @@ -231,10 +231,13 @@ class BundleReaderTest : public ::testing::Test { value3.set_null_value(google::protobuf::NULL_VALUE); ProtoValue value4; value4.mutable_array_value(); + ProtoValue value5; + value5.mutable_map_value(); document.mutable_fields()->insert({"\0\ud7ff\ue000\uffff\"", value1}); document.mutable_fields()->insert({"\"(╯°□°)╯︵ ┻━┻\"", value2}); document.mutable_fields()->insert({"nValue", value3}); document.mutable_fields()->insert({"emptyArray", value4}); + document.mutable_fields()->insert({"emptyMap", value5}); return document; }