From bc9dff9d4c78a22a947ff4c57e9bb465d59872a6 Mon Sep 17 00:00:00 2001 From: "Johannes J. Schmidt" Date: Wed, 4 Jun 2014 11:01:27 +0200 Subject: [PATCH] Fixed named parameter followed by optional parameter --- index.js | 2 +- package.json | 2 +- test/named-parameter-test.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 99b28a3..d7b9c31 100644 --- a/index.js +++ b/index.js @@ -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; }, {}); diff --git a/package.json b/package.json index cc24417..69c2804 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docuri", - "version": "4.0.1", + "version": "4.0.2", "description": "Rich document ids for CouchDB", "main": "index.js", "scripts": { diff --git a/test/named-parameter-test.js b/test/named-parameter-test.js index 79b4700..bfc414e 100644 --- a/test/named-parameter-test.js +++ b/test/named-parameter-test.js @@ -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(); +});