Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Blob of data with zero length. #12694

Merged
merged 5 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Allow blob of data with zero length. (#11773, #12620)

# 10.24.0
- [feature] Enable queries with range & inequality filters on multiple fields. (#12416)

Expand Down
34 changes: 34 additions & 0 deletions Firestore/Swift/Tests/Integration/CodableIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,40 @@ class CodableIntegrationTests: FSTIntegrationTestCase {
}
}

func testDataBlob() throws {
struct Model: Encodable {
var name: String
var data: Data
var emptyData: Data
}
let model = Model(
name: "name",
data: Data([1, 2, 3, 4]),
emptyData: Data()
)

let docToWrite = documentRef()

for flavor in allFlavors {
try setData(from: model, forDocument: docToWrite, withFlavor: flavor)

let data = readDocument(forRef: docToWrite)

XCTAssertEqual(data["data"] as! Data, Data([1, 2, 3, 4]), "Failed with flavor \(flavor)")
XCTAssertEqual(data["emptyData"] as! Data, Data(), "Failed with flavor \(flavor)")
}

db.disableNetwork()
ehsannas marked this conversation as resolved.
Show resolved Hide resolved
defer {
db.enableNetwork()
}

try docToWrite.setData(from: model)
let data = readDocument(forRef: docToWrite)
XCTAssertEqual(data["data"] as! Data, Data([1, 2, 3, 4]), "Failed with flavor offline docRef")
XCTAssertEqual(data["emptyData"] as! Data, Data(), "Failed with flavor offline docRef")
}

func testExplicitNull() throws {
struct Model: Encodable {
var name: String
Expand Down
1 change: 1 addition & 0 deletions Firestore/core/src/nanopb/nanopb_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ inline NSData* _Nonnull MakeNSData(const ByteString& str) {
}

inline NSData* _Nonnull MakeNSData(const pb_bytes_array_t* _Nullable data) {
if (data == nil) return [[NSData alloc] init];
return [[NSData alloc] initWithBytes:data->bytes length:data->size];
}

Expand Down
Loading