Skip to content
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
9 changes: 6 additions & 3 deletions packages/google_cloud_firestore/lib/src/field_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,17 @@ void _validateUserInput(

case Map<Object?, Object?>():
for (final entry in value.entries) {
final keyPath = switch (entry.key) {
final FieldPath fp => fp,
final String s => FieldPath([s]),
_ => FieldPath([entry.key.toString()]),
};
_validateUserInput(
arg,
entry.value,
description: description,
options: options,
path: path == null
? FieldPath.from(entry.key)
: path._appendPath(FieldPath.from(entry.key)),
path: path == null ? keyPath : path._appendPath(keyPath),
level: level + 1,
inArray: inArray,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,38 @@ void main() {

expect(collections, containsAll([a, b]));
});

group('map keys with "/" characters', () {
test('set() round-trips a map with "/" in key', () async {
final docRef = firestore.doc('activities/new-activity');

await docRef.set({
'activityType': 'activityA',
'agents': {'products/product-a': 5.0},
});

final data = (await docRef.get()).data()!;
expect(data['activityType'], 'activityA');
expect(
(data['agents']! as Map<String, Object?>)['products/product-a'],
5.0,
);
});

test('update() round-trips a map value with "/" in key', () async {
final docRef = firestore.doc('activities/update-activity');
await docRef.set({'activityType': 'activityA'});

await docRef.update({
'agents': {'products/product-b': 10.0},
});

final data = (await docRef.get()).data()!;
expect(
(data['agents']! as Map<String, Object?>)['products/product-b'],
10.0,
);
});
});
});
}
33 changes: 33 additions & 0 deletions packages/google_cloud_firestore/test/unit/firestore_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,39 @@ void main() {
final batch = firestore.batch();
expect(batch, isA<WriteBatch>());
});

group('set() with map keys containing "/"', () {
test('accepts a top-level map value with "/" in key', () {
final firestore = Firestore(
settings: const Settings(projectId: 'test'),
);
final batch = firestore.batch();
final docRef = firestore.doc('activities/new-activity');

expect(
() => batch.set(docRef, {
'activityType': 'activityA',
'agents': {'products/product-a': 5.0},
}),
returnsNormally,
);
});

test('accepts nested maps with "/" in keys', () {
final firestore = Firestore(
settings: const Settings(projectId: 'test'),
);
final batch = firestore.batch();
final docRef = firestore.doc('col/doc');

expect(
() => batch.set(docRef, {
'refs': {'users/alice': true, 'users/bob': false},
}),
returnsNormally,
);
});
});
});

group('bulkWriter()', () {
Expand Down
Loading