Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function mergeDataIntoQueryString<T extends RequestPayload>(
const url = new URL(href.toString(), typeof window === 'undefined' ? 'http://localhost' : window.location.toString())

if (hasDataForQueryString) {
const parseOptions = { ignoreQueryPrefix: true, parseArrays: false }
const parseOptions = { ignoreQueryPrefix: true, arrayLimit: 0 }
url.search = qs.stringify(
{ ...qs.parse(url.search, parseOptions), ...data },
{
Expand Down
21 changes: 21 additions & 0 deletions tests/core/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ test.describe('url.ts', () => {
expect(data).toEqual({})
})

test('merges new data into an existing query string with array values', () => {
const [href, data] = mergeDataIntoQueryString('get', '/search?frameworks[]=react&frameworks[]=vue', {
q: 'bar',
})

expect(href).toBe('/search?frameworks[]=react&frameworks[]=vue&q=bar')
expect(data).toEqual({})
})

test('merges new data into an existing query string with array values using index notation', () => {
const [href, data] = mergeDataIntoQueryString(
'get',
'/search?frameworks[0]=react&frameworks[1]=vue',
{ q: 'bar' },
'indices',
)

expect(href).toBe('/search?frameworks[0]=react&frameworks[1]=vue&q=bar')
expect(data).toEqual({})
})

test('overwrites existing keys in the query string when they also exist in the data', () => {
const [href, data] = mergeDataIntoQueryString('get', '/search?q=old', { q: 'new' })

Expand Down