Skip to content

Commit

Permalink
Keys are also already decoded by URLSearchParams
Browse files Browse the repository at this point in the history
  • Loading branch information
diogob committed Nov 1, 2023
1 parent 9e4c02b commit fc2cb44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/input-resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ describe('inputFromSearch', () => {

it('takes keys encoded as URI components', () => {
const qs = new URLSearchParams()
qs.append('some%20colors[0]', 'blue')
qs.append('some%20colors[1]', 'red ish')
qs.append('some colors[0]', 'blue')
qs.append('some colors[1]', 'red ish')
assertEquals(subject.inputFromSearch(qs), {
'some colors': ['blue', 'red ish'],
})
Expand Down
3 changes: 1 addition & 2 deletions src/input-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const inputFromSearch = (queryString: URLSearchParams) => {

return pairs
.sort(([keyA], [keyB]) => keyA.localeCompare(keyB))
.reduce((parsed, [encodedKey, value]) => {
const key = decodeURIComponent(encodedKey)
.reduce((parsed, [key, value]) => {
const compositeKey = key.match(/([^\[\]]*)(\[.*\].*)$/)
if (compositeKey) {
const [, rootKey, subKeys] = compositeKey
Expand Down

0 comments on commit fc2cb44

Please sign in to comment.