From d3190b83f3ac900b0e2076b42f5aeb9e082d0d01 Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Fri, 10 Jul 2020 14:38:12 +0200 Subject: [PATCH 1/4] Add tests checking for point path normalization --- .../test/internal_tests/pointer_test.dart | 7 +++++++ 1 file changed, 7 insertions(+) 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); + }); }); } From efaa96d1694de69005b64d04bf69e9305c951204 Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Fri, 10 Jul 2020 14:38:31 +0200 Subject: [PATCH 2/4] Fix pointer path normalisation --- .../lib/src/internal/pointer.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..42fe68cdbe65 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; + String get path { + return components.join('/'); + } /// Pointer components of the path. /// From 052f9495caa0a6d2281019f0e86a67bcaf698fc9 Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Fri, 10 Jul 2020 14:46:45 +0200 Subject: [PATCH 3/4] Update pointer path docs --- .../lib/src/internal/pointer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 42fe68cdbe65..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 @@ -14,7 +14,7 @@ class Pointer { components = path.split('/').where((element) => element.isNotEmpty).toList(); - /// The Firestore path the [Pointer] was initialized with. + /// The Firestore normalized path of the [Pointer]. String get path { return components.join('/'); } From 97291304ad96e070e98322c28b00dc45169a8728 Mon Sep 17 00:00:00 2001 From: Dennis Kugelmann Date: Fri, 10 Jul 2020 15:19:10 +0200 Subject: [PATCH 4/4] Add CHANGELOG for path changes and equality checks --- packages/cloud_firestore/cloud_firestore/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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()`.