use path-to-regexp
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jonathan Ong · committed by Jonathan Ong · parent 5572897 · Browse files · 3 files·+5 added−47 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+5 added−47 removed
- other:+5 added−47 removed
Provenance
- Commit
3321055- Tree
69eea8f- Author
Jonathan Ong <jonathanrichardong@gmail.com>- Committer
Jonathan Ong <jonathanrichardong@gmail.com>- Parent
5572897
3 files changed+5 added−47 removed
modified:lib/router/layer.js+4 added-7 removed
1212345672 unmodified lines101112131314151617141516171842 unmodified linesvar utils = require('../utils') , debug = require('debug')('express:router:layer')var utils = require('../utils');var pathRegexp = require('path-to-regexp');var debug = require('debug')('express:router:layer');
function Layer(path, options, fn) { if (!(this instanceof Layer)) { return new Layer(path, options, fn);2 unmodified lines debug('new %s', path); options = options || {}; this.path = path; this.params = {}; this.regexp = utils.pathRegexp(path , this.keys = [] , options.sensitive , options.strict , options.end); this.regexp = pathRegexp(path, this.keys = [], options); this.handle = fn;}
/**42 unmodified linesmodified:lib/utils.js-40 removed
118 unmodified lines119 return ret;120 }121 122 /**123- * Normalize the given path string,124- * returning a regular expression.125- *126- * An empty array should be passed,127- * which will contain the placeholder128- * key names. For example "/user/:id" will129- * then contain ["id"].130- *131- * @param {String|RegExp|Array} path132- * @param {Array} keys133- * @param {Boolean} sensitive134- * @param {Boolean} strict135- * @param {Boolean} end (whether to append $ to regex)136- * @return {RegExp}137- * @api private138- */139-140-exports.pathRegexp = function(path, keys, sensitive, strict, end) {141- if (toString.call(path) == '[object RegExp]') return path;142- if (Array.isArray(path)) path = '(' + path.join('|') + ')';143- path = path144- .concat(strict ? '' : '/?')145- .replace(/\/\(/g, '(?:/')146- .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, function(_, slash, format, key, capture, optional, star){147- keys.push({ name: key, optional: !! optional });148- slash = slash || '';149- return ''150- + (optional ? '' : slash)151- + '(?:'152- + (optional ? slash : '')153- + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'154- + (optional || '')155- + (star ? '(/*)?' : '');156- })157- .replace(/([\/.])/g, '\\$1')158- .replace(/\*/g, '(.*)');159- return new RegExp('^' + path + ((end) ? '$' : ''), sensitive ? '' : 'i');160-}161-162-/**123 * Parse the `req` url with memoization.124 *125 * @param {ServerRequest} req126 * @return {Object}18 unmodified linesmodified:package.json+1 added
34 unmodified lines35363738394041424336 unmodified lines34 unmodified lines "utils-merge": "1.0.0", "escape-html": "1.0.1", "qs": "0.6.6", "serve-static": "1.0.1", "path-to-regexp": "0.1.0", "debug": ">= 0.7.3 < 1" }, "devDependencies": { "ejs": "~0.8.4",36 unmodified lines