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

fix(firestore, web): fix an issue where nested object could be incorrectly decoded from JSObjects #12272

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ void runFieldValueTests() {
},
skip: true,
);

testWidgets('query should restore nested Timestamp', (_) async {
DocumentReference<Map<String, dynamic>> doc =
await initializeTest('nested-timestamp');
await Future.wait([
doc.set({
'nested': {
'timestamp': Timestamp.fromDate(DateTime(2020)),
},
'timestamp': Timestamp.fromDate(DateTime(2020)),
}),
]);

final snapshot = await doc.get();

expect(snapshot.data()!['timestamp'], isA<Timestamp>());
expect(snapshot.data()!['nested']['timestamp'], isA<Timestamp>());
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ dynamic dartify(dynamic object) {
}

if (dartObject is Map) {
return dartObject
.map((key, value) => MapEntry(key as String, dartify(value)));
final Map<String, dynamic> map = {};
for (final key in dartObject.keys) {
final value = dartObject[key];
if (value is Map) {
map[key as String] =
value.map((key, value) => MapEntry(key, dartify(value)));
} else if (value is List) {
map[key as String] = value.map(dartify).toList();
} else {
map[key as String] = dartify(value);
}
}
return map;
}

return dartObject;
Expand Down
Loading