-
-
Notifications
You must be signed in to change notification settings - Fork 969
Closed
Labels
bugSomething does not work as it shouldSomething does not work as it should
Description
Describe the bug
- Node.js version: v16.4.0
- OS & version: Mac 10.15.7
- Got version: 12.0.0-beta.1
Actual behavior
When passing a URLSearchParams
with duplicate keys, only the last key/value is used in the URL search params.
const searchParams = new URLSearchParams();
searchParams.append("a", "100");
searchParams.append("a", "200");
searchParams.append("a", "300");
const response = await got.get(
'https://example.com',
{
searchParams: searchParams,
}
);
console.log(response.request.options.url);
Results in the following URL:
URL {
href: 'https://example.com?a=300',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '?a=300',
searchParams: URLSearchParams { 'a' => '300' },
hash: ''
}
Expected behavior
I expected the duplicate search param keys to have been included. The same happens even if I toString()
the URLSearchParams
myself and pass that in. Seems like Got is parsing and re-encoding the params.
URL {
href: 'https://example.com?a=100&a=200&a=300',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '?a=100&a=200&a=300',
searchParams: URLSearchParams { 'a' => '100', 'a' => '200', 'a' => '300' },
hash: ''
}
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
Metadata
Metadata
Assignees
Labels
bugSomething does not work as it shouldSomething does not work as it should