Merge pull request #24 from zerotacg/optional-parameter-with-trailing-slash

optional parameter with a trailing slash
pull/25/head
Johannes Jörg Schmidt 9 years ago
commit 2b2eb939bd

@ -102,7 +102,7 @@ function insertParameters(route, obj) {
// massage optional parameter
return str
.replace(/\(\/\)(\/|$)/g, '$1')
.replace(/\(\/\)/g, '')
.replace(/[)(]/g, '');
}

@ -22,3 +22,14 @@ test('surrounded optional parameter', function(t) {
t.end();
});
test('optional parameter with trailing slash', function(t) {
var page = docuri.route('(:id/)page');
t.deepEqual(page('page'), {}, 'parsed page returns empty object');
t.deepEqual(page('mypage/page'), { id: 'mypage' }, 'parsed page has "id" set to "mypage"');
t.equal(page(), 'page', 'stringified empty page results in "page"');
t.equal(page({ id: 'mypage' }), 'mypage/page', 'stringified page results in "mypage/page"');
t.end();
});

Loading…
Cancel
Save