Skip to content

Vuexfire bug in walkGet() when reference field contains a dot #932

@Phr33d0m

Description

@Phr33d0m

Steps to reproduce the behavior

  1. Go to Cloud Firestore and create a collection 'books'
  2. Add a 'book' document with a field containing a dot (.) and make it a reference to somewhere else.
    2.1. An example would be this field: T.HANKS => (reference) /authors/T.HANKS
    2.2. Firebase allows you to have dots inside document and field names
  3. Bind this book document in your code return bindFirestoreRef('author', db.collection('authors').doc('T.HANKS'))

Expected behavior

A clear and concise description of what you expected to happen.

Actual behavior

Vuefire doesn't like that, and dies here:

/**
 * Walks a path inside an object
 * walkGet({ a: { b: true }}), 'a.b') -> true
 * @param obj
 * @param path
 */
function walkGet(obj, path) {
    // TODO: development warning when target[key] does not exist
    return path.split('.').reduce(function (target, key) { return target[key]; }, obj);
}

Additional information

The stacktrace is something like this:

Uncaught TypeError: Cannot read property 'HANKS' of undefined
    at eval (vuexfire.esm.js?5a83:18)
    at Array.reduce (<anonymous>)
    at walkGet (vuexfire.esm.js?5a83:18)
    at updateDataFromDocumentSnapshot (vuexfire.esm.js?5a83:271)
    at Array.eval (vuexfire.esm.js?5a83:280)
    at next (index.cjs.js?92d4:15375)
    at eval (index.cjs.js?92d4:13446)

Notice the property it errs with is "HANKS" but the key is "T.HANKS".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions