Skip to content

[cloud_firestore_platform_interface] Pointer equality not normalising paths #2928

@IchordeDionysos

Description

@IchordeDionysos

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:

  1. Android/iOS implementation: No normalization there. That's okay as I believe the normalization should not be done by the implementing library.
  2. MethodChannelFirebaseFirestore: Not there either. I think it's okay.
  3. MethodChannelCollectionReference: No normalization. It's okay.
  4. 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 DocumentReferences/CollectionReferences the equality of the underlying Pointers is checked.

So, let's play it through:

  1. DocumentReference.==: Path property of references is compared.
  2. DocumentReference.path: Path is returned from Pointer.
  3. Pointer.path: Path from Pointer is returned as provided by the user, see above steps.

To Reproduce
Steps to reproduce the behavior:

  1. Import cloud_firestore
  2. Use this source code:
final db = FirebaseFirestore.instance;
print(db.collection('test') == db.collection('/test'));
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions