Skip to content
Browse files

Update duplicated normalizePath() function.

This brings route path handling in line with current versions
of Connect by adding support for capture groups in paths:

  app.resource('/:path(*)', ...);
  • Loading branch information...
1 parent d08fb49 commit c0753336b8195f44ab4418d7eec7e45d03123548 @laurie71 laurie71 committed
Showing with 10 additions and 10 deletions.
  1. +10 −10 lib/middleware/resource.js
View
20 lib/middleware/resource.js
@@ -185,16 +185,16 @@ function normalizePath(path, keys) {
path = path
.concat('/?')
.replace(/\/\(/g, '(?:/')
- .replace(/(\/)?(\.)?:(\w+)(\?)?/g, function(_, slash, format, key, optional) {
- keys.push(key);
- slash = slash || '';
- return ''
- + (optional ? '' : slash)
- + '(?:'
- + (optional ? slash : '')
- + (format || '') + '([^/.]+))'
- + (optional || '');
- })
+ .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){
+ keys.push(key);
+ slash = slash || '';
+ return ''
+ + (optional ? '' : slash)
+ + '(?:'
+ + (optional ? slash : '')
+ + (format || '') + (capture || '([^/]+?)') + ')'
+ + (optional || '');
+ })
.replace(/([\/.])/g, '\\$1')
.replace(/\*/g, '(.+)');
return new RegExp('^' + path + '$', 'i');

0 comments on commit c075333

Please sign in to comment.
Something went wrong with that request. Please try again.