Skip to content

Commit 87e951c

Browse files
committed
Use arrayLimit: 0 instead of parseArrays: false for qs.parse
1 parent f7787d5 commit 87e951c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/core/src/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function mergeDataIntoQueryString<T extends RequestPayload>(
6161
const url = new URL(href.toString(), typeof window === 'undefined' ? 'http://localhost' : window.location.toString())
6262

6363
if (hasDataForQueryString) {
64-
const parseOptions = { ignoreQueryPrefix: true, parseArrays: false }
64+
const parseOptions = { ignoreQueryPrefix: true, arrayLimit: 0 }
6565
url.search = qs.stringify(
6666
{ ...qs.parse(url.search, parseOptions), ...data },
6767
{

tests/core/url.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ test.describe('url.ts', () => {
2929
expect(data).toEqual({})
3030
})
3131

32+
test('merges new data into an existing query string with array values', () => {
33+
const [href, data] = mergeDataIntoQueryString('get', '/search?frameworks[]=react&frameworks[]=vue', { q: 'bar' })
34+
35+
expect(href).toBe('/search?frameworks[]=react&frameworks[]=vue&q=bar')
36+
expect(data).toEqual({})
37+
})
38+
39+
test('merges new data into an existing query string with array values using index notation', () => {
40+
const [href, data] = mergeDataIntoQueryString('get', '/search?frameworks[0]=react&frameworks[1]=vue', { q: 'bar' }, 'indices')
41+
42+
expect(href).toBe('/search?frameworks[0]=react&frameworks[1]=vue&q=bar')
43+
expect(data).toEqual({})
44+
})
45+
3246
test('overwrites existing keys in the query string when they also exist in the data', () => {
3347
const [href, data] = mergeDataIntoQueryString('get', '/search?q=old', { q: 'new' })
3448

0 commit comments

Comments
 (0)