Fixed query params composing; (#5018)

* Fixes #4999;

* Added regression test;
This commit is contained in:
Dmitriy Mozgovoy 2022-10-05 22:29:50 +03:00 committed by GitHub
parent d61dbede95
commit 3e4d52171e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -301,9 +301,14 @@ export default function httpAdapter(config) {
auth && headers.delete('authorization');
const path = parsed.pathname.concat(parsed.searchParams);
let path;
try {
buildURL(path, config.params, config.paramsSerializer).replace(/^\?/, '');
path = buildURL(
parsed.pathname + parsed.search,
config.params,
config.paramsSerializer
).replace(/^\?/, '');
} catch (err) {
const customErr = new Error(err.message);
customErr.config = config;
@ -315,7 +320,7 @@ export default function httpAdapter(config) {
headers.set('Accept-Encoding', 'gzip, deflate, br', false);
const options = {
path: buildURL(path, config.params, config.paramsSerializer).replace(/^\?/, ''),
path,
method: method,
headers: headers.toJSON(),
agents: { http: config.httpAgent, https: config.httpsAgent },

View File

@ -0,0 +1,13 @@
import assert from 'assert';
import axios from '../../../index.js';
describe('issues', function () {
describe('4999', function () {
it('should not fail with query parsing', async function () {
const {data} = await axios.get('https://postman-echo.com/get?foo1=bar1&foo2=bar2');
assert.strictEqual(data.args.foo1, 'bar1');
assert.strictEqual(data.args.foo2, 'bar2');
});
});
});