Skip to content

Commit

Permalink
Added + support to pathtoRegexp()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 6, 2012
1 parent 6975e18 commit f874eea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@

function pathtoRegexp(path, keys, sensitive, strict) {
if (path instanceof RegExp) return path;
if (path instanceof Array) path = '(' + path.join('|') + ')';
if (path instanceof Array) path = '(' + path.join('|') + ')';
path = path
.concat(strict ? '' : '/?')
.replace(/\/\(/g, '(?:/')
.replace(/\+/g, '__plus__')
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){
keys.push({ name: key, optional: !! optional });
slash = slash || '';
Expand All @@ -293,6 +294,7 @@
+ (optional || '');
})
.replace(/([\/.])/g, '\\$1')
.replace(/__plus__/g, '(.+)')
.replace(/\*/g, '(.*)');
return new RegExp('^' + path + '$', sensitive ? '' : 'i');
};
Expand Down

0 comments on commit f874eea

Please sign in to comment.