diff --git a/packages/cloud_firestore/cloud_firestore/CHANGELOG.md b/packages/cloud_firestore/cloud_firestore/CHANGELOG.md index 8dfe2ef57dcc..c36855d771f9 100644 --- a/packages/cloud_firestore/cloud_firestore/CHANGELOG.md +++ b/packages/cloud_firestore/cloud_firestore/CHANGELOG.md @@ -19,7 +19,9 @@ Along with the below changes, the plugin has undergone a quality of life update **`CollectionReference`**: - **BREAKING**: Getting a collection parent document via `parent()` has been changed to a getter `parent`. +- **BREAKING**: Getting the collection `path` now always returns the `path` without leading and trailing slashes. - **DEPRECATED**: Calling `document()` is deprecated in favor of `doc()`. +- **FIX**: Equality checking of `CollectionReference` now does not depend on the original path used to create the `CollectionReference`. **`Query`**: - **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 - **BREAKING**: `setData`/`set` has been updated to accept an instance of `SetOptions` (see below, supports `mergeFields`). - **BREAKING**: `get()` has been updated to accept an instance of `GetOptions` (see below). - **BREAKING**: Getting a document parent collection via `parent()` has been changed to a getter `parent`. +- **BREAKING**: Getting the document `path` now always returns the `path` without leading and trailing slashes. - **DEPRECATED**: `documentID` has been deprecated in favor of `id`. - **DEPRECATED**: `setData()` has been deprecated in favor of `set()`. - **DEPRECATED**: `updateData()` has been deprecated in favor of `update()`. +- **FIX**: Equality checking of `DocumentReference` now does not depend on the original path used to create the `DocumentReference`. **`DocumentChange`**: - **DEPRECATED**: Calling `document()` is deprecated in favor of `doc()`. diff --git a/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/internal/pointer.dart b/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/internal/pointer.dart index 4c89d68cd285..f38a001e6f2b 100644 --- a/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/internal/pointer.dart +++ b/packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/internal/pointer.dart @@ -9,13 +9,15 @@ /// to reduce code repetition and improve testability. class Pointer { /// Create instance of [Pointer] - Pointer(this.path) + Pointer(String path) : assert(path != null), components = path.split('/').where((element) => element.isNotEmpty).toList(); - /// The Firestore path the [Pointer] was initialized with. - final String path; + /// The Firestore normalized path of the [Pointer]. + String get path { + return components.join('/'); + } /// Pointer components of the path. /// diff --git a/packages/cloud_firestore/cloud_firestore_platform_interface/test/internal_tests/pointer_test.dart b/packages/cloud_firestore/cloud_firestore_platform_interface/test/internal_tests/pointer_test.dart index b4474127137b..39a5c23e4f58 100644 --- a/packages/cloud_firestore/cloud_firestore_platform_interface/test/internal_tests/pointer_test.dart +++ b/packages/cloud_firestore/cloud_firestore_platform_interface/test/internal_tests/pointer_test.dart @@ -66,5 +66,12 @@ void main() { expect(Pointer('foo') == Pointer('foo'), true); expect(Pointer('foo') == Pointer('foo/bar'), false); }); + + test('Pointer equality with un-normalized paths', () { + expect(Pointer('foo') == Pointer('/foo'), true); + expect(Pointer('foo') == Pointer('/foo/bar'), false); + expect(Pointer('foo') == Pointer('foo/'), true); + expect(Pointer('foo') == Pointer('foo/bar/'), false); + }); }); }