Skip to content

Commit f0d9c2d

Browse files
MohamedAhmed12mohamed.gadposva
authored
fix(query): cast query values to strings (fix #2131) (#3232)
* 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]>
1 parent 84398ae commit f0d9c2d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/util/query.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export function resolveQuery (
2929
parsedQuery = {}
3030
}
3131
for (const key in extraQuery) {
32-
parsedQuery[key] = extraQuery[key]
32+
const value = extraQuery[key]
33+
parsedQuery[key] = Array.isArray(value) ? value.map(v => '' + v) : '' + value
3334
}
3435
return parsedQuery
3536
}

test/unit/specs/query.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ describe('Query utils', () => {
1919
arr: ['1', null, '2']
2020
})
2121
})
22+
23+
it('should cast query values into string', () => {
24+
const query = resolveQuery('foo=bar&foo=k', { baz: 1 })
25+
expect(query.baz).toBe('1')
26+
})
27+
it('should cast query array values into string', () => {
28+
const query = resolveQuery('foo=bar&foo=k', { baz: [1, '2'] })
29+
expect(query.baz).toEqual(['1', '2'])
30+
})
2231
})
2332

2433
describe('stringifyQuery', () => {

0 commit comments

Comments
 (0)