diff --git a/lib/adapters/http.js b/lib/adapters/http.js index b864afeb18..35722b3106 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -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 }, diff --git a/test/unit/regression/bugs.js b/test/unit/regression/bugs.js new file mode 100644 index 0000000000..1a660507b1 --- /dev/null +++ b/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'); + }); + }); +});