Skip to content

Commit

Permalink
fix(query): cast query values to strings (fix #2131) (#3232)
Browse files Browse the repository at this point in the history
* fix(query): Fix query props should be casted into string (fix #2131)

* Apply suggestions from code review

* Update test/unit/specs/query.spec.js

Co-authored-by: mohamed.gad <[email protected]>
Co-authored-by: Eduardo San Martin Morote <[email protected]>
  • Loading branch information
3 people authored Jun 18, 2020
1 parent 84398ae commit f0d9c2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/util/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export function resolveQuery (
parsedQuery = {}
}
for (const key in extraQuery) {
parsedQuery[key] = extraQuery[key]
const value = extraQuery[key]
parsedQuery[key] = Array.isArray(value) ? value.map(v => '' + v) : '' + value
}
return parsedQuery
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/specs/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ describe('Query utils', () => {
arr: ['1', null, '2']
})
})

it('should cast query values into string', () => {
const query = resolveQuery('foo=bar&foo=k', { baz: 1 })
expect(query.baz).toBe('1')
})
it('should cast query array values into string', () => {
const query = resolveQuery('foo=bar&foo=k', { baz: [1, '2'] })
expect(query.baz).toEqual(['1', '2'])
})
})

describe('stringifyQuery', () => {
Expand Down

0 comments on commit f0d9c2d

Please sign in to comment.