Skip to content

Commit 549d677

Browse files
dpatwardhansindresorhus
andauthoredJun 11, 2020
Fix sorting existing query params in URL when sort option is false (#265)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent d3da28b commit 549d677

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ exports.stringifyUrl = (input, options) => {
361361

362362
const url = removeHash(input.url).split('?')[0] || '';
363363
const queryFromUrl = exports.extract(input.url);
364-
const parsedQueryFromUrl = exports.parse(queryFromUrl);
364+
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
365365

366366
const query = Object.assign(parsedQueryFromUrl, input.query);
367367
let queryString = exports.stringify(query, options);

‎test/stringify-url.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ test('stringify URL from the result of `parseUrl` with query string that contain
5252
const parsedUrl = queryString.parseUrl(url);
5353
t.deepEqual(queryString.stringifyUrl(parsedUrl, {encode: false}), url);
5454
});
55+
56+
test('stringify URL without sorting existing query params', t => {
57+
t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?C=3&A=1', query: {D: 4, B: 2}}, {sort: false}), 'https://foo.bar?C=3&A=1&D=4&B=2');
58+
});

0 commit comments

Comments
 (0)
Please sign in to comment.