elemMatch throws TypeError: value is null if array has null element
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- databases
Research direction
Start in index.es.js at the $elemMatch matcher and its rowFilter call, following the stack trace around getFieldFromDoc. Reproduce the issue with an array containing an object followed by null, then verify that matching no longer throws and preserves the intended elemMatch result.
Written by the indexing model from the issue text.
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
});
}
[...]
- Dominant language
- JavaScript
- Stars
- 17.6k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/pouchdb
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
apache/pouchdb#9265 · 1 comment · 4 reactions · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·
-
client-controller-update ta-bot-triage team-money-movement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-mobile#36594 ·