diff --git a/index.js b/index.js index 10da346..0f312c4 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,7 @@ function compileRoute (route, options) { pathParams[key] = values[key] } } else { - queryParams[key] = values[key] + if (typeof values[key] !== 'undefined') queryParams[key] = values[key] } }) diff --git a/tests/test.js b/tests/test.js index 4975c89..9e21968 100644 --- a/tests/test.js +++ b/tests/test.js @@ -339,6 +339,17 @@ module.exports = { test.done() }, + 'should not stringify undefined query params': function (test) { + var mapper = urlMapper({ query: true }) + + test.equal(mapper.stringify('/:foo', { + foo: 'bar', + bar: undefined + }), '/bar') + + test.done() + }, + 'should parse stringified object including params not defined in route': function (test) { var mapper = urlMapper({ query: true }) var object = {