Skip to content

elemMatch throws TypeError: value is null if array has null element #9103

Description

@smesgr9000

pouchdb-find throws TypeError: value is null if array has null element on non-first position.
Example:
{ test: [{ foo: "blub"}, null] }

Exception:

TypeError: value is null
    getFieldFromDoc index.es.js:10
    rowFilter index.es.js:396
    rowFilter index.es.js:393
    elemMatch index.es.js:557
    $elemMatch index.es.js:556
    match index.es.js:473
    matchSelector index.es.js:417
    matchSelector index.es.js:413
    rowFilter index.es.js:401
    rowFilter index.es.js:393

Code:

var matchers = {
  "$elemMatch": function(doc, userValue, parsedField, docFieldValue) {
    if (!Array.isArray(docFieldValue)) {
      return false;
    }
    if (docFieldValue.length === 0) {
      return false;
    }
    if (typeof docFieldValue[0] === "object" && docFieldValue[0] !== null) {
      return docFieldValue.some(function(val) {
        return rowFilter(val, userValue, Object.keys(userValue)); // << val is null
      });
    }
[...]

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions