Skip to content

Commit 38dae7b

Browse files
committed
Fix stringifyUrl not respecting passed in options
Fixes #409
1 parent fc532f8 commit 38dae7b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export function stringifyUrl(object, options) {
516516
const queryFromUrl = extract(object.url);
517517

518518
const query = {
519-
...parse(queryFromUrl, {sort: false}),
519+
...parse(queryFromUrl, {sort: false, ...options}),
520520
...object.query,
521521
};
522522

test/stringify-url.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,26 @@ test('stringify URL from the result of `parseUrl` with query string that contain
5858
test('stringify URL without sorting existing query params', t => {
5959
t.is(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');
6060
});
61+
62+
test('stringifyUrl uses parsing options when parsing existing query from url', t => {
63+
const currentUrl = 'https://localhost:3000/?array[]=item1';
64+
65+
const result = queryString.stringifyUrl(
66+
{
67+
url: currentUrl,
68+
query: {
69+
array: [
70+
'item1',
71+
'item2',
72+
],
73+
},
74+
},
75+
{
76+
arrayFormat: 'bracket',
77+
skipEmptyString: true,
78+
skipNull: true,
79+
},
80+
);
81+
82+
t.is(result, 'https://localhost:3000/?array[]=item1&array[]=item2');
83+
});

0 commit comments

Comments
 (0)