Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/node_modules/pouchdb-find/src/adapters/local/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ function filterInclusiveStart(rows, targetValue, index) {
docKey.pop();
}
}
// docs missing the indexed field are excluded from the index entirely
// to avoid a null pointer exception in collate.
var isMissingKey = Array.isArray(docKey) ?
docKey.some(function (k) { return k === undefined; }) :
docKey === undefined;
if (isMissingKey) {
++startAt;
continue;
}

//ABS as we just looking for values that don't match
if (Math.abs(collate(docKey, targetValue)) > 0) {
// no need to filter any further; we're past the key
Expand Down
1 change: 1 addition & 0 deletions tests/find/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<script src='./test-suite-2/test.kitchen-sink-2.js'></script>
<script src='./test-issues/test.issue7810.js'></script>
<script src='./test-issues/test.issue8389.js'></script>
<script src='./test-issues/test.issue9183.js'></script>
<script type="text/javascript" src="../integration/webrunner.js"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions tests/find/test-issues/test.issue9183.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";

describe("test.issue9183.js", function () {
var adapter = testUtils.adapterType();
var db = null;
var dbName = null;

beforeEach(function () {
dbName = testUtils.adapterUrl(adapter, "issue9183");
db = new PouchDB(dbName);
return db.bulkDocs([
{ _id: "doc1", name: "Mario" },
{ _id: "doc2" }, // Missing 'name' field
]);
});

afterEach(function (done) {
testUtils.cleanup([dbName], done);
});

it("should not throw a null pointer exception when a document is missing the indexed field", function () {
return db
.createIndex({
index: { fields: ["name"] }
})
.then(function () {
return db.find({
selector: {
name: { $gt: null } // Try $gt instead of $gte
}
});
})
.then(function (res) {
res.docs.should.have.length(1);
res.docs[0]._id.should.equal("doc1");
});
});
});
Loading