This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/main by this push:
new 2973eba omit undefined query string parameters instead of sending the
string "undefined". Fixes issue #377 (#378)
2973eba is described below
commit 2973ebabad03c41d194afa71c803db1ee0ef432f
Author: Clemens Stolle <[email protected]>
AuthorDate: Tue Oct 27 13:12:11 2026 +0000
omit undefined query string parameters instead of sending the string
"undefined". Fixes issue #377 (#378)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
lib/nano.js | 6 +++
test/design.view.test.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+)
diff --git a/lib/nano.js b/lib/nano.js
index 25c59be..4238c86 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -343,6 +343,12 @@ module.exports = exports = function dbScope (cfg) {
qs[key] = JSON.stringify(qs[key])
}
})
+ // omit undefined parameters, rather than sending the string 'undefined'
+ Object.keys(qs).forEach(function (key) {
+ if (qs[key] === undefined) {
+ delete qs[key]
+ }
+ })
}
// HTTP request body
diff --git a/test/design.view.test.js b/test/design.view.test.js
index a36f24a..34a56da 100644
--- a/test/design.view.test.js
+++ b/test/design.view.test.js
@@ -138,6 +138,101 @@ test('should be able to access a MapReduce view with
queries - POST /db/_design/
mockAgent.assertNoPendingInterceptors()
})
+test('should omit undefined opts from the query string - GET
/db/_design/ddoc/_view/viewname - db.view', async () => {
+ // mocks
+ const response = {
+ rows: [
+ { key: 'BA', value: 21 }
+ ]
+ }
+ mockPool
+ .intercept({ path: '/db/_design/ddoc/_view/viewname?include_docs=true' })
+ .reply(200, response, JSON_HEADERS)
+
+ // test GET /db/_design/ddoc/_view/viewname
+ const db = nano.db.use('db')
+ const p = await db.view('ddoc', 'viewname', { limit: undefined,
include_docs: true })
+ assert.deepEqual(p, response)
+ mockAgent.assertNoPendingInterceptors()
+})
+
+test('should omit undefined JSON-encoded opts from the query string - GET
/db/_design/ddoc/_view/viewname - db.view', async () => {
+ // mocks
+ const response = {
+ rows: [
+ { key: 'BA', value: 21 }
+ ]
+ }
+ mockPool
+ .intercept({ path: '/db/_design/ddoc/_view/viewname?group=true' })
+ .reply(200, response, JSON_HEADERS)
+
+ // test GET /db/_design/ddoc/_view/viewname
+ const db = nano.db.use('db')
+ const p = await db.view('ddoc', 'viewname', { start_key: undefined, end_key:
undefined, group: true })
+ assert.deepEqual(p, response)
+ mockAgent.assertNoPendingInterceptors()
+})
+
+test('should omit undefined keys from the query string - GET
/db/_design/ddoc/_view/viewname - db.view', async () => {
+ // mocks
+ const response = {
+ rows: [
+ { key: 'BA', value: 21 }
+ ]
+ }
+ mockPool
+ .intercept({ path: '/db/_design/ddoc/_view/viewname?reduce=false' })
+ .reply(200, response, JSON_HEADERS)
+
+ // test GET /db/_design/ddoc/_view/viewname
+ const db = nano.db.use('db')
+ const p = await db.view('ddoc', 'viewname', { keys: undefined, reduce: false
})
+ assert.deepEqual(p, response)
+ mockAgent.assertNoPendingInterceptors()
+})
+
+test('should omit undefined opts from the query string with keys - POST
/db/_design/ddoc/_view/viewname - db.view', async () => {
+ // mocks
+ const keys = ['BA', 'BD']
+ const response = {
+ rows: [
+ { key: 'BA', value: 21 }
+ ]
+ }
+ mockPool
+ .intercept({
+ method: 'post',
+ path: '/db/_design/ddoc/_view/viewname?include_docs=true',
+ body: JSON.stringify({ keys })
+ })
+ .reply(200, response, JSON_HEADERS)
+
+ // test POST /db/_design/ddoc/_view/viewname
+ const db = nano.db.use('db')
+ const p = await db.view('ddoc', 'viewname', { keys, limit: undefined,
include_docs: true })
+ assert.deepEqual(p, response)
+ mockAgent.assertNoPendingInterceptors()
+})
+
+test('should still send null JSON-encoded opts in the query string - GET
/db/_design/ddoc/_view/viewname - db.view', async () => {
+ // mocks
+ const response = {
+ rows: [
+ { key: null, value: 23515 }
+ ]
+ }
+ mockPool
+ .intercept({ path: '/db/_design/ddoc/_view/viewname?startkey=null' })
+ .reply(200, response, JSON_HEADERS)
+
+ // test GET /db/_design/ddoc/_view/viewname
+ const db = nano.db.use('db')
+ const p = await db.view('ddoc', 'viewname', { startkey: null })
+ assert.deepEqual(p, response)
+ mockAgent.assertNoPendingInterceptors()
+})
+
test('should be able to handle 404 - db.view', async () => {
// mocks
const response = {