From 189012f4f035e80008460d49a20fbb6003724d07 Mon Sep 17 00:00:00 2001
From: brucearctor <5032356+brucearctor@users.noreply.github.com.>
Date: Sun, 15 Mar 2026 16:16:43 -0700
Subject: [PATCH 1/2] (#9183) - Fix null pointer exception when searching with
index for missing field
filterInclusiveStart throws a TypeError when collating a key
for a document that is missing the indexed field. This commit adds
a check to skip documents where the required index key is undefined,
matching CouchDB's behavior of excluding such documents from the index.
---
.../pouchdb-find/src/adapters/local/utils.js | 9 +++++
tests/find/index.html | 1 +
tests/find/test-issues/test.issue9183.js | 38 +++++++++++++++++++
3 files changed, 48 insertions(+)
create mode 100644 tests/find/test-issues/test.issue9183.js
diff --git a/packages/node_modules/pouchdb-find/src/adapters/local/utils.js b/packages/node_modules/pouchdb-find/src/adapters/local/utils.js
index f97d21cf52..0a2ff2c473 100644
--- a/packages/node_modules/pouchdb-find/src/adapters/local/utils.js
+++ b/packages/node_modules/pouchdb-find/src/adapters/local/utils.js
@@ -75,6 +75,15 @@ function filterInclusiveStart(rows, targetValue, index) {
docKey.pop();
}
}
+
+ // docs missing the indexed field are excluded from the index entirely
+ // or they shouldn't cause a null pointer exception in collate.
+ let isMissingKey = Array.isArray(docKey) ? docKey.some(k => 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
diff --git a/tests/find/index.html b/tests/find/index.html
index 1566612eb0..c8dd4460be 100644
--- a/tests/find/index.html
+++ b/tests/find/index.html
@@ -60,6 +60,7 @@
+