Fixed named parameter followed by optional parameter

pull/12/head
Johannes J. Schmidt 11 years ago
parent e751d71494
commit bc9dff9d4c

@ -41,7 +41,7 @@ function routeToRegExp(src) {
keys = keys.reduce(function(memo, key) {
var value = '\\' + key;
memo[key] = new RegExp(value + '(\\/|\\)|$)');
memo[key] = new RegExp(value + '(\\/|\\)|\\(|$)');
return memo;
}, {});

@ -1,6 +1,6 @@
{
"name": "docuri",
"version": "4.0.1",
"version": "4.0.2",
"description": "Rich document ids for CouchDB",
"main": "index.js",
"scripts": {

@ -18,3 +18,12 @@ test('two named parameters', function(t) {
t.end();
});
test('named parameter followed by optional parameter', function(t) {
docuri.route('page/:id(/:optional)', 'page');
t.deepEqual(docuri.page('page/mypage'), { id: 'mypage' }, 'parsed page has "id" set to "mypage"');
t.equal(docuri.page({ id: 'mypage', optional: 'number' }), 'page/mypage/number', 'stringified page results in "page/mypage/number"');
t.end();
});

Loading…
Cancel
Save