Skip to content

Commit

Permalink
Remove support for encoded query param names
Browse files Browse the repository at this point in the history
  • Loading branch information
santino committed Mar 16, 2023
1 parent 3155ed4 commit e7d2ace
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-concurrent-router",
"version": "1.5.1",
"version": "1.5.2",
"description": "Performant routing embracing React concurrent UI patterns",
"author": "Santino Puleio",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/useSearchParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('useSearchParams', () => {
expect(mockHistoryPush).toHaveBeenCalledWith(
{
pathname: '/home',
search: '?baz=qux&foo=bar&quux%2F=corge%3D'
search: '?baz=qux&foo=bar&quux/=corge%3D'
},
{}
)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('utils', () => {
qux: 'quux',
'baz/': 'qux='
})
).toBe('?baz%2F=qux%3D&foo=bar&qux=quux')
).toBe('?baz/=qux%3D&foo=bar&qux=quux')
})

it('returns expected value on simple object with array values', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ export const sortAndStringifyRequestParams = params => {
)
.reduce((identifier, element) => {
const rawParamValue = params[element.value]
const paramName = encodeURIComponent(element.value)
const paramValue = Array.isArray(rawParamValue)
? rawParamValue.reduce((params, value, index) => {
const encodedValue = encodeURIComponent(value)
return params.concat(
index >= 1 ? `&${paramName}=${encodedValue}` : encodedValue
index >= 1 ? `&${element.value}=${encodedValue}` : encodedValue
)
}, '')
: encodeURIComponent(rawParamValue)
return `${identifier}${!identifier ? '?' : '&'}${paramName}=${paramValue}`
return `${identifier}${!identifier ? '?' : '&'}${
element.value
}=${paramValue}`
}, '')
}

Expand Down

0 comments on commit e7d2ace

Please sign in to comment.