Skip to content

Commit a53ec6e

Browse files
Don't fail on empty bundles (#9140)
1 parent 902adf8 commit a53ec6e

File tree

6 files changed

+51
-38
lines changed

6 files changed

+51
-38
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 25 additions & 33 deletions
Large diffs are not rendered by default.

Firestore/Source/Public/FirebaseFirestore/FIRDocumentReference.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ NS_SWIFT_NAME(DocumentReference)
109109
* to be written.
110110
* @param mergeFields An `NSArray` that contains a list of `NSString` or `FIRFieldPath` elements
111111
* specifying which fields to merge. Fields can contain dots to reference nested fields within
112-
* the document. If your input sets any field to an empty dictionary, any nested field is overwritten.
112+
* the document. If your input sets any field to an empty dictionary, any nested field is
113+
* overwritten.
113114
*/
114115
- (void)setData:(NSDictionary<NSString *, id> *)documentData mergeFields:(NSArray<id> *)mergeFields;
115116

Firestore/Source/Public/FirebaseFirestore/FIRTransaction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ NS_SWIFT_NAME(Transaction)
8080
* @param document A reference to the document whose data should be overwritten.
8181
* @param mergeFields An `NSArray` that contains a list of `NSString` or `FIRFieldPath` elements
8282
* specifying which fields to merge. Fields can contain dots to reference nested fields within
83-
* the document. If your input sets any field to an empty dictionary, any nested field is overwritten.
83+
* the document. If your input sets any field to an empty dictionary, any nested field is
84+
* overwritten.
8485
* @return This `FIRTransaction` instance. Used for chaining method calls.
8586
*/
8687
// clang-format off

Firestore/Source/Public/FirebaseFirestore/FIRWriteBatch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ NS_SWIFT_NAME(WriteBatch)
8282
* @param document A reference to the document whose data should be overwritten.
8383
* @param mergeFields An `NSArray` that contains a list of `NSString` or `FIRFieldPath` elements
8484
* specifying which fields to merge. Fields can contain dots to reference nested fields within
85-
* the document. If your input sets any field to an empty dictionary, any nested field is overwritten.
85+
* the document. If your input sets any field to an empty dictionary, any nested field is
86+
* overwritten.
8687
* @return This `FIRWriteBatch` instance. Used for chaining method calls.
8788
*/
8889
// clang-format off

Firestore/core/src/bundle/bundle_serializer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ Timestamp DecodeTimestamp(JsonReader& reader, const json& version) {
9595
}
9696
} else {
9797
decoded = TimestampInternal::FromUntrustedSecondsAndNanos(
98-
reader.RequiredInt<int64_t>("seconds", version),
99-
reader.RequiredInt<int32_t>("nanos", version));
98+
reader.OptionalInt<int64_t>("seconds", version, 0),
99+
reader.OptionalInt<int32_t>("nanos", version, 0));
100100
}
101101

102102
if (!decoded.ok()) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,24 @@ class BundleReaderTest : public ::testing::Test {
326326
std::vector<std::string> elements_;
327327
};
328328

329+
TEST_F(BundleReaderTest, ReadsEmptyBundle) {
330+
ProtoBundleMetadata metadata;
331+
metadata.set_id("bundle-1");
332+
metadata.set_version(1);
333+
metadata.set_total_documents(0);
334+
metadata.mutable_create_time(); // No seconds/nanos
335+
metadata.set_total_bytes(0);
336+
ProtoBundleElement element;
337+
*element.mutable_metadata() = metadata;
338+
339+
std::string metadata_str;
340+
MessageToJsonString(element, &metadata_str);
341+
std::string bundle = std::to_string(metadata_str.size()) + metadata_str;
342+
343+
BundleReader reader(bundle_serializer, ToByteStream(bundle));
344+
VerifyFullBundleParsed(reader, "bundle-1", testutil::Version(0));
345+
}
346+
329347
TEST_F(BundleReaderTest, ReadsQueryAndDocument) {
330348
AddNamedQuery(LimitQuery());
331349
AddNamedQuery(LimitToLastQuery());

0 commit comments

Comments
 (0)