Skip to content
Myr

Fixed param() with multiple placeholders

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

authored by visionmedia · committed by visionmedia · parent 3090ca3 · Browse files · 2 files+8 added−7 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+8 added−7 removed

  • tests:+0 added−1 removed
  • other:+8 added−6 removed

2 files+8 added−7 removed

modified:lib/express/core.js+8 added-6 removed
17 unmodified lines
18})1920// --- Router2122var captures = [],23 params = {}2425Router = Class({23 captures: [],24 params: {},26 route: function(request){27 this.request = request28 return this.matchingRoute().run()29 },
13 unmodified lines
43 */4445 match: function(route) {46 if (this.request.method.toLowerCase() == route.method)46 if (this.captures = this.request.uri.path.match(route.path)) {47 if (captures = this.request.uri.path.match(route.path)) {48 this.mapParams()49 return true50 }51 },52 53 mapParams: function() {54 for (var i = 0, len = keys.length; i < len; ++i)54 this.params[keys[i]] = this.captures[i+1]55 params[keys[i]] = captures[i+1]56 }57})5859// --- Server
44 unmodified lines
104 return path.replace(/[\s\/]*$/g, '')105}106107param = function(key) {107 return Express.server.router.params[key]108 return params[key]109}110111jsonEncode = function(object) {112 return JSON.stringify(object)
60 unmodified lines
173 * @return {regexp}174 * @api private175 */176176var keys = []177var keys178function pathToRegexp(path) {179 if (path instanceof RegExp) return path180 keys = []181 return new RegExp('^' + 182 escapeRegexp(path.replace(/:(\w+)/g, function(_, key){183 keys.push(key)184 return '(.*?)'
41 unmodified lines
modified:spec/spec.core.routing.js-1 removed