Skip to content
Myr

Docs

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

authored by visionmedia · committed by visionmedia · parent 9bc091d · Browse files · 1 file+29 added−1 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+29 added−1 removed

  • other:+29 added−1 removed

1 file+29 added−1 removed

modified:lib/express.core.js+29 added-1 removed
155 unmodified lines
156 normalizePath : function(path) {157 return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')158 },159 160 /**161 * Normalize _path_. When a RegExp it is simply returned,162 * otherwise a string is converted to a regular expression163 * surrounded by ^$. So /user/:id/edit would become:164 *165 * \^/user/(.*?)\/edit\$/166 *167 * Each param key (:id) will be captured and placed in the168 * params array, so param('id') would give the string captured.169 *170 * @param {string} path171 * @return {regexp}172 * @api public173 */174 175 pathToRegexp : function(path) {176 if (path.constructor == RegExp) return path177 Express.regexpKeys = []178 path = path.replace(/:(\w+)/, function(key){179 Express.regexpKeys.push(key)180 return '(.*?)'181 })167 return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$')182 return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$', 'i')183 },184 185 /**186 * Escape RegExp _chars_ in _string_. Where _chars_ 187 * defaults to regular expression special characters.188 *189 * _chars_ should be a space delimited list of characters,190 * for example '[ ] ( )'.191 *192 * @param {string} string193 * @param {string} chars194 * @return {Type}195 * @api public196 */197 198 escapeRegexp : function(string, chars) {199 var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')200 return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')201 },
139 unmodified lines