Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query): Fix query props should be casted into string (fix #2131) #3232

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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
10 changes: 10 additions & 0 deletions test/unit/specs/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ 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')
})

posva marked this conversation as resolved.
Show resolved Hide resolved
it('should cast query array values into string', () => {
const query = resolveQuery('foo=bar&foo=k', { baz: [1, '2'] })
expect(query.baz).toEqual(['1', '2'])
})
posva marked this conversation as resolved.
Show resolved Hide resolved
})

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