Repository navigation
omit undefined query string parameters instead of sending the string "undefined" - #378
Merged
Merged
Conversation
…"undefined". Fixes issue apache#377 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Since nano 11 moved to
fetch,relax()builds the query string withnew URLSearchParams(qs). That turns an option whose value isundefinedintokey=undefined. Forstartkey/endkey/key/keys/start_key/end_keythe same thing happens afterJSON.stringify(undefined). CouchDB rejects these requests with 400s such asInvalid value for integer: "undefined"andinvalid UTF-8 JSON. nano 10'sqs-based serialiser skippedundefinedvalues, 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
undefinedentries fromqsinrelax(), right after the existing JSON-encoding loop. That way the fix applies to every API that sends a query string, not only views.nullis left unchanged on purpose.startkey: nullis a valid key and is still sent asstartkey=null. For other parametersnullis an explicit value, and nano 10 didn't drop it either (it was serialised askey=).Testing recommendations
npm test: all 239 tests pass. New tests intest/design.view.test.js:db.view(..., { limit: undefined, include_docs: true })→GET ?include_docs=truedb.view(..., { start_key: undefined, end_key: undefined, group: true })→GET ?group=truedb.view(..., { keys: undefined, reduce: false })→GET ?reduce=false(keysis falsy, so it stays a GET)db.view(..., { keys, limit: undefined, include_docs: true })→POST ?include_docs=truewith{ keys }in the bodydb.view(..., { startkey: null })still sends?startkey=nullThe first four fail on
mainwithMockNotMatchedErrorfor paths such as?include_docs=true&limit=undefined, and pass with this change. Thelib/nano.jslines added here are fully covered (measured withnode --test --experimental-test-coverage).standardreports no new issues in either changed file.GitHub issue number
Fixes #377
Related Pull Requests
None.
Checklist
This change was prepared with Claude Code and reviewed by me before submitting.
🤖 Generated with Claude Code