Skip to content

Commit

Permalink
fix(parse): ensure optional parameters return undefined and not "unde…
Browse files Browse the repository at this point in the history
…fined"
  • Loading branch information
Adam Schroder committed Aug 2, 2016
1 parent 613c82c commit e59295c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compileRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function compileRoute (route, options) {

for (var i = 1; i < match.length; ++i) {
var key = keys[i - 1]
var value = decodeURIComponent(match[i])
if (value[0] === ':') {
var value = match[i] && decodeURIComponent(match[i])
if (value && value[0] === ':') {
result[key] = URLON.parse(value)
} else {
result[key] = value
Expand Down
11 changes: 11 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ module.exports = {
test.equal(mapper.stringify('/:foo', { foo: 'bar', bar: 'baz' }), '/bar#@bar=baz')
test.deepEqual(mapper.parse('/:foo', '/bar#@bar=baz'), { foo: 'bar', bar: 'baz' })

test.done()
},

'should parse optional paramters as undefined': function (test) {
var mapper = urlMapper()

test.deepEqual(mapper.parse('/:foo/:bar?', '/bar/'), {
foo: 'bar',
bar: undefined
})

test.done()
}
}
Expand Down

0 comments on commit e59295c

Please sign in to comment.