unit test and adjustments for using optional parameter with a trailing slash

pull/24/head
Tobias Peters 10 years ago
parent 3ed0d3cef0
commit f7a90694bd

@ -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