klaemo opened a new pull request, #378:
URL: https://github.com/apache/couchdb-nano/pull/378
## 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
- [x] Code is written and works correctly;
- [x] Changes are covered by tests;
- [x] 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](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]