Skip to content

Commit

Permalink
fix(firestore, web): fix an issue where nested object could be incorr…
Browse files Browse the repository at this point in the history
…ectly decoded from JSObjects (#12272)
  • Loading branch information
Lyokone committed Feb 2, 2024
1 parent 7de58e4 commit bd27d1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit bd27d1d

Please sign in to comment.