Skip to content

Commit

Permalink
Fixed query params composing; (#5018)
Browse files Browse the repository at this point in the history
* Fixes #4999;

* Added regression test;
  • Loading branch information
DigitalBrainJS committed Oct 5, 2022
1 parent d61dbed commit 3e4d521
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/adapters/http.js
Expand Up @@ -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;
Expand All @@ -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 },
Expand Down
13 changes: 13 additions & 0 deletions test/unit/regression/bugs.js
@@ -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');
});
});
});

0 comments on commit 3e4d521

Please sign in to comment.