Skip to content

omit undefined query string parameters instead of sending the string "undefined" - #378

Merged
glynnbird merged 1 commit into
apache:mainfrom
klaemo:fix/omit-undefined-query-params
Oct 27, 2026
Merged

glynnbird merged 1 commit into
apache:mainfrom
klaemo:fix/omit-undefined-query-params

Conversation

@klaemo

@klaemo klaemo commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Overview

Since nano 11 moved to fetch, relax() builds the query string with new URLSearchParams(qs). That turns an option whose value is undefined into key=undefined. For startkey/endkey/key/keys/start_key/end_key the same thing happens after JSON.stringify(undefined). CouchDB rejects these requests with 400s such as Invalid value for integer: "undefined" and invalid UTF-8 JSON. nano 10's qs-based serialiser skipped undefined values, so this is a regression for code that passes optional values straight through, e.g. db.view(ddoc, view, { limit: opts.limit }).

This PR deletes undefined entries from qs in relax(), right after the existing JSON-encoding loop. That way the fix applies to every API that sends a query string, not only views.

null is left unchanged on purpose. startkey: null is a valid key and is still sent as startkey=null. For other parameters null is an explicit value, and nano 10 didn't drop it either (it was serialised as key=).

Testing recommendations

npm test: all 239 tests pass. New tests in test/design.view.test.js:

  • db.view(..., { limit: undefined, include_docs: true }) → GET ?include_docs=true
  • db.view(..., { start_key: undefined, end_key: undefined, group: true }) → GET ?group=true
  • db.view(..., { keys: undefined, reduce: false }) → GET ?reduce=false (keys is falsy, so it stays a GET)
  • db.view(..., { keys, limit: undefined, include_docs: true }) → POST ?include_docs=true with { keys } in the body
  • db.view(..., { startkey: null }) still sends ?startkey=null

The first four fail on main with MockNotMatchedError for paths such as ?include_docs=true&limit=undefined, and pass with this change. The lib/nano.js lines added here are fully covered (measured with node --test --experimental-test-coverage). standard reports no new issues in either changed file.

GitHub issue number

Fixes #377

Related Pull Requests

None.

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes; (no documentation change needed: this restores the nano 10 behaviour)

This change was prepared with Claude Code and reviewed by me before submitting.

🤖 Generated with Claude Code

…"undefined". Fixes issue apache#377

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@glynnbird glynnbird left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glynnbird
glynnbird merged commit 2973eba into apache:main Oct 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nano 11 sends undefined query parameters as the literal string "undefined"

2 participants