Skip to content

Commit

Permalink
Do not encode null values for params
Browse files Browse the repository at this point in the history
  • Loading branch information
mergebandit committed Nov 29, 2017
1 parent 9443978 commit 3980765
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class Route {

const toQuerystring = obj => Object.keys(obj).map(key => {
let value = obj[key]
if (value === null) {
value = ''
}
if (Array.isArray(value)) {
value = value.join('/')
}
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe('Routes', () => {
expect(setup('a').route.getUrls()).toEqual({as: '/a', href: '/a?'})
})

test('do not pass "null" for params that have null values', () => {
const {route} = setup('a', '/a/:b/:c?')
const params = {b: 'b', c: null}
const expected = {as: '/a/b', href: '/a?b=b&c='}
expect(route.getUrls(params)).toEqual(expected)
expect(setup('a').route.getUrls()).toEqual({as: '/a', href: '/a?'})
})

test('ensure "as" when path match is empty', () => {
expect(setup('a', '/:a?').route.getAs()).toEqual('/')
})
Expand Down

0 comments on commit 3980765

Please sign in to comment.