-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Describe the bug
Not sure did not test it yet. (Will write a test and open a PR if the problem is real).
The pointer implementation splits the path into components AND removes any empty element/removes leading/trailing slashes.
Which is basically what we want!
However, when checking for equality the implementation does not use any normalized form, but rather uses the user-provided path for equality checking, which leads to unexpected inequalities of document and collection references.
Look at the way DocumentReferences are created:
- Android/iOS implementation: No normalization there. That's okay as I believe the normalization should not be done by the implementing library.
- MethodChannelFirebaseFirestore: Not there either. I think it's okay.
- MethodChannelCollectionReference: No normalization. It's okay.
- Pointer: No normalization. This is problematic.
In the pointer, the low-level, internal representation of references there is no normalization of the path.
When checking for equality of two DocumentReference
s/CollectionReference
s the equality of the underlying Pointer
s is checked.
So, let's play it through:
- DocumentReference.==: Path property of references is compared.
- DocumentReference.path: Path is returned from
Pointer
. - Pointer.path: Path from
Pointer
is returned as provided by the user, see above steps.
To Reproduce
Steps to reproduce the behavior:
- Import
cloud_firestore
- Use this source code:
final db = FirebaseFirestore.instance;
print(db.collection('test') == db.collection('/test'));
- See that
false
is printed out.
Expected behavior
db.collection('test') == db.collection('/test')
should evaluate to true
.
Additional context
Discovered this bug while looking at the implementation of the Pointer
class.
Will update this issue once I tested it out and validated it.