apache / apache/pouchdb

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

Open
#9,103 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

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
});
}
[...]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.