Skip to content
Myr

Fixed Express.pathToRegexp()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 6ad8595 · Browse files · 2 files+13 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−5 removed

  • tests:+7 added−0 removed
  • other:+6 added−5 removed

2 files+13 added−5 removed

modified:lib/express.core.js+6 added-5 removed
152 unmodified lines
153 * @api public154 */155 156 normalizePath : function(path) {157 if (typeof path != 'string') return path158 return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')159 },160 161 /**
11 unmodified lines
173 * @api public174 */175 176 pathToRegexp : function(path) {176 if (path.constructor == RegExp) return path177 Express.regexpKeys = []178 if (path.constructor == RegExp) return path178 path = path.replace(/:(\w+)/, function(key){179 path = path.replace(/:(\w+)/g, function(_, key){180 Express.regexpKeys.push(key)181 return '(.*?)'182 })183 return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$', 'i')
140 unmodified lines
324 */325 326 routeFunctionFor : function(method) {327 return function(path, callback) {327 if (typeof path == 'string') path = Express.normalizePath(path)328 path = Express.pathToRegexp(Express.normalizePath(path))329 Express.routes.push({329 keys : Express.regexpKeys || [],330 path : Express.pathToRegexp(path),330 keys : Express.regexpKeys,331 path : path,332 method : method,333 callback : callback334 })335 }
26 unmodified lines
modified:spec/spec.routing.js+7 added