Skip to content

Commit ae68344

Browse files
authored
Support empty map in Firestore bundle (#12312)
1 parent e8ec72b commit ae68344

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Firestore/core/src/bundle/bundle_serializer.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,16 @@ Message<google_firestore_v1_Value> BundleSerializer::DecodeValue(
584584

585585
Message<google_firestore_v1_MapValue> BundleSerializer::DecodeMapValue(
586586
JsonReader& reader, const json& map_json) const {
587-
if (!map_json.is_object() || !map_json.contains("fields")) {
588-
reader.Fail("mapValue is not a valid map");
587+
if (!map_json.is_object()) {
588+
reader.Fail("mapValue is not a valid object");
589589
return {};
590590
}
591+
592+
// Empty map doesn't have `fields` field.
593+
if (!map_json.contains("fields")) {
594+
return {};
595+
}
596+
591597
const auto& fields = map_json.at("fields");
592598
if (!fields.is_object()) {
593599
reader.Fail("mapValue's 'field' is not a valid map");

Firestore/core/test/unit/bundle/bundle_reader_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,13 @@ class BundleReaderTest : public ::testing::Test {
231231
value3.set_null_value(google::protobuf::NULL_VALUE);
232232
ProtoValue value4;
233233
value4.mutable_array_value();
234+
ProtoValue value5;
235+
value5.mutable_map_value();
234236
document.mutable_fields()->insert({"\0\ud7ff\ue000\uffff\"", value1});
235237
document.mutable_fields()->insert({"\"(╯°□°)╯︵ ┻━┻\"", value2});
236238
document.mutable_fields()->insert({"nValue", value3});
237239
document.mutable_fields()->insert({"emptyArray", value4});
240+
document.mutable_fields()->insert({"emptyMap", value5});
238241

239242
return document;
240243
}

0 commit comments

Comments
 (0)