Skip to content
Myr

Added support for /user/:foo? to wrap as (?:\/(.*?))?

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

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

  • tests:+8 added−1 removed
  • other:+12 added−1 removed

2 files+20 added−2 removed

modified:lib/express/core.js+12 added-1 removed
185 unmodified lines
186 *187 * Each param key (:id) will be captured and placed in the188 * params array, so param('id') would give the string captured.189 *190 * The following are valid routes:191 *192 * - /user/:id193 * - /user/:id?194 * - /report.:format195 *196 * @param {string} path197 * @return {regexp}198 * @api private199 */
2 unmodified lines
202function pathToRegexp(path) {203 if (path instanceof RegExp) return path204 keys = []205 return new RegExp('^' + 200 escapeRegexp(path.replace(/:(\w+)/g, function(_, key){206 escapeRegexp(path207 .replace(/\/:(\w+)\?/g, function(_, key){208 keys.push(key)209 return '(?:\/(.*?))?'210 })211 .replace(/:(\w+)/g, function(_, key){212 keys.push(key)213 return '(.*?)'214 }), '/ [ ]') + '$', 'i')215}216
38 unmodified lines
modified:spec/spec.core.helpers.js+8 added-1 removed