Skip to content
Myr

Fixed route param issue when multiple routes are present

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

Better fix for this coming soon

authored by visionmedia · committed by visionmedia · parent f72e5e2 · Browse files · 1 file+12 added−9 removed
This commit

State

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

Diff stats

1 file+12 added−9 removed

  • other:+12 added−9 removed

1 file+12 added−9 removed

modified:lib/express/core.js+12 added-9 removed
20 unmodified lines
21 *22 * @param {string} method23 * @param {string} path24 * @param {function} fn25 * @param {hash} options26 * @api private27 */28 29 init: function(method, path, fn, options){30 this.method = method31 this.originalPath = path32 this.path = pathToRegexp(normalizePath(path))33 this.keys = Express.keys34 this.fn = fn35 },36 37 /**
65 unmodified lines
103104 match: function(route) {105 if (this.request.method.toLowerCase() == route.method)106 if (this.captures = this.request.uri.path.match(route.path)) {105 this.mapParams()107 this.mapParams(route)108 return true109 }110 },111 112 /**111 * Map #captures to #params.113 * Map #captures to #params based on the114 * given _route_ keys.115 *116 * @param {Route} route117 * @api private118 */119 116 mapParams: function() {117 for (var i = 0, len = keys.length; i < len; ++i)118 this.params[keys[i]] = this.captures[i+1]120 mapParams: function(route) {121 for (var i = 0, len = route.keys.length; i < len; ++i)122 this.params[route.keys[i]] = this.captures[i+1]123 }124})125126// --- Server
63 unmodified lines
190 * @return {regexp}191 * @api private192 */193190var keys194function pathToRegexp(path) {195 Express.keys = []196 if (path instanceof RegExp) return path193 keys = []197 return new RegExp('^' + 198 escapeRegexp(path199 .replace(/\/:(\w+)\?/g, function(_, key){197 keys.push(key)200 Express.keys.push(key)201 return '(?:\/(.*?))?'202 })203 .replace(/:(\w+)/g, function(_, key){201 keys.push(key)204 Express.keys.push(key)205 return '(.*?)'206 }), '/ [ ]') + '$', 'i')207}208
9 unmodified lines