Skip to content

Commit 2bfa0f6

Browse files
fix(firestore): normalize Firestore pointer path (#2929)
1 parent 6e41bcb commit 2bfa0f6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/cloud_firestore/cloud_firestore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Along with the below changes, the plugin has undergone a quality of life update
1919

2020
**`CollectionReference`**:
2121
- **BREAKING**: Getting a collection parent document via `parent()` has been changed to a getter `parent`.
22+
- **BREAKING**: Getting the collection `path` now always returns the `path` without leading and trailing slashes.
2223
- **DEPRECATED**: Calling `document()` is deprecated in favor of `doc()`.
24+
- **FIX**: Equality checking of `CollectionReference` now does not depend on the original path used to create the `CollectionReference`.
2325

2426
**`Query`**:
2527
- **BREAKING**: The internal query logic has been overhauled to better assert invalid queries locally.
@@ -38,9 +40,11 @@ Along with the below changes, the plugin has undergone a quality of life update
3840
- **BREAKING**: `setData`/`set` has been updated to accept an instance of `SetOptions` (see below, supports `mergeFields`).
3941
- **BREAKING**: `get()` has been updated to accept an instance of `GetOptions` (see below).
4042
- **BREAKING**: Getting a document parent collection via `parent()` has been changed to a getter `parent`.
43+
- **BREAKING**: Getting the document `path` now always returns the `path` without leading and trailing slashes.
4144
- **DEPRECATED**: `documentID` has been deprecated in favor of `id`.
4245
- **DEPRECATED**: `setData()` has been deprecated in favor of `set()`.
4346
- **DEPRECATED**: `updateData()` has been deprecated in favor of `update()`.
47+
- **FIX**: Equality checking of `DocumentReference` now does not depend on the original path used to create the `DocumentReference`.
4448

4549
**`DocumentChange`**:
4650
- **DEPRECATED**: Calling `document()` is deprecated in favor of `doc()`.

packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/internal/pointer.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
/// to reduce code repetition and improve testability.
1010
class Pointer {
1111
/// Create instance of [Pointer]
12-
Pointer(this.path)
12+
Pointer(String path)
1313
: assert(path != null),
1414
components =
1515
path.split('/').where((element) => element.isNotEmpty).toList();
1616

17-
/// The Firestore path the [Pointer] was initialized with.
18-
final String path;
17+
/// The Firestore normalized path of the [Pointer].
18+
String get path {
19+
return components.join('/');
20+
}
1921

2022
/// Pointer components of the path.
2123
///

packages/cloud_firestore/cloud_firestore_platform_interface/test/internal_tests/pointer_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,12 @@ void main() {
6666
expect(Pointer('foo') == Pointer('foo'), true);
6767
expect(Pointer('foo') == Pointer('foo/bar'), false);
6868
});
69+
70+
test('Pointer equality with un-normalized paths', () {
71+
expect(Pointer('foo') == Pointer('/foo'), true);
72+
expect(Pointer('foo') == Pointer('/foo/bar'), false);
73+
expect(Pointer('foo') == Pointer('foo/'), true);
74+
expect(Pointer('foo') == Pointer('foo/bar/'), false);
75+
});
6976
});
7077
}

0 commit comments

Comments
 (0)