Describe the bug
- Node.js version: -
- OS & version: -
got.mergeOptions isn't merging instances of URLSearchParams. According to the README is should merge them.
Actual behavior
It looks like later instances of URLSearchParams just overwrite earlier values. (see code sample)
Expected behavior
It should merge the two URLSearchParams instances.
Code to reproduce
const got = require('got');
got.mergeOptions({ searchParams: new URLSearchParams({ foo: 1 }) }, { searchParams: new URLSearchParams({ bar: 2 }) });
// => { ... searchParams: URLSearchParams { 'bar' => '2' } }
Checklist
I think some code got deleted in #921.
merge.ts got moved https://github.com/sindresorhus/got/pull/921/files#diff-5e2f9cb0db248d822e1b167d5ccf8e07. Before the move it had code to deal with instances of URLSearchParams:
|
if (targetValue instanceof URLSearchParams && sourceValue instanceof URLSearchParams) { |
|
const params = new URLSearchParams(); |
|
|
|
const append = (value: string, key: string): void => params.append(key, value); |
|
targetValue.forEach(append); |
|
sourceValue.forEach(append); |
|
|
|
// @ts-ignore https://github.com/microsoft/TypeScript/issues/31661 |
|
target[key] = params; |
After the move it's missing the code to handle URLSearchParams: https://github.com/szmarczak/got/blob/a7e73f2fe89b1eca00d2f8fff71dffb2caf68c16/source/utils/merge.ts
Describe the bug
got.mergeOptionsisn't merging instances ofURLSearchParams. According to the README is should merge them.Actual behavior
It looks like later instances of
URLSearchParamsjust overwrite earlier values. (see code sample)Expected behavior
It should merge the two URLSearchParams instances.
Code to reproduce
Checklist
I think some code got deleted in #921.
merge.tsgot moved https://github.com/sindresorhus/got/pull/921/files#diff-5e2f9cb0db248d822e1b167d5ccf8e07. Before the move it had code to deal with instances ofURLSearchParams:got/source/merge.ts
Lines 13 to 21 in 9f4fe33
After the move it's missing the code to handle
URLSearchParams: https://github.com/szmarczak/got/blob/a7e73f2fe89b1eca00d2f8fff71dffb2caf68c16/source/utils/merge.ts