Skip to content

Commit

Permalink
Support empty map in Firestore bundle (#12312)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu authored Jan 25, 2024
1 parent e8ec72b commit ae68344
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Firestore/core/src/bundle/bundle_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,16 @@ Message<google_firestore_v1_Value> BundleSerializer::DecodeValue(

Message<google_firestore_v1_MapValue> 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");
Expand Down
3 changes: 3 additions & 0 deletions Firestore/core/test/unit/bundle/bundle_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ae68344

Please sign in to comment.