searchParams in init hookssindresorhus/ky#861 · @atharvasingh7007 · MIT · licence
a slice of a larger PR (2 files) · see it all
searchParams tuple arrays before init hooks mutate them
- prevent tuple edits from leaking into later requests on the same instance
- add a regression test covering the supported [[key, value]] search params form
## Root cause
cloneInitHookOptions() is supposed to give init hooks a request-local mutable copy of the options, but searchParams in tuple-array form only got a shallow outer array copy. Mutating an existing tuple like options.searchParams[0][1] = ... changed the shared default tuple, so the next request inherited the previous hook mutation.
## Fix
- add a cloneSearchParametersForInitHook() helper that deep-copies tuple arrays while preserving the other supported searchParams input forms
- keep the existing cloning behavior for strings, objects, and URLSearchParams
- add an end-to-end init-hook regression that proves tuple-array defaults no longer leak between requests
## Testing
- npm run build
- npx ava test/hooks.ts --match "init hook*do not leak across requests"
- npx ava test/hooks.ts --match "init hook tuple searchParams mutations do not leak across requests"
## Notes
npm test in this Windows checkout still hits upstream xo project-service parsing errors for the repo's test files before it reaches AVA. The targeted hook tests and build above passed locally.// files changed