Merge pull request #56 from apihlaja/insert-falsy-parameters

Allow inserting falsy values, excluding undefined
pull/52/merge
Johannes Jörg Schmidt 8 years ago committed by GitHub
commit b7c944c8dd

@ -89,7 +89,7 @@ function insertParameters(route, obj) {
Object.keys(route.keys).forEach(function(key) {
var k = key.substr(1);
var value = obj[k] || '';
var value = (obj[k] !== undefined) ? obj[k] : '';
if (Array.isArray(value)) {
value = value.map(encodeURIComponent).join('/');

@ -10,6 +10,18 @@ test('named parameter', function(t) {
t.end();
});
test('insert falsy parameter values', function(t) {
var page = docuri.route('page/:id');
t.deepEqual(page({}), 'page/', 'stringifies without id');
t.deepEqual(page({id: undefined}), 'page/', 'stringifies without id');
t.deepEqual(page({id: 0}), 'page/0', 'inserts "0"');
t.deepEqual(page({id: false}), 'page/false', 'inserts "false"');
t.deepEqual(page({id: null}), 'page/null', 'inserts "null"');
t.end();
});
test('two named parameters', function(t) {
var content = docuri.route('page/:page_id/content/:id');

Loading…
Cancel
Save