Skip to content
Myr

normalizePath() in Route#normalize()

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

authored by visionmedia · committed by visionmedia · parent 2d75362 · Browse files · 1 file+17 added−17 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+17 added−17 removed

  • other:+17 added−17 removed

1 file+17 added−17 removed

modified:lib/express/core.js+17 added-17 removed
5 unmodified lines
6process.mixin(require('express/helpers'))7process.mixin(require('express/mime'))8process.mixin(require('express/dsl'))910// --- Helpers1112/**13 * Normalize the given _path_.14 * Strips trailing slashes and whitespace.15 *16 * @param {string} path17 * @return {string}18 * @api private19 */2021function normalizePath(path) {22 return path.replace(/[\s\/]*$/g, '')23}2425// --- Route2627Route = Class({28
14 unmodified lines
43 44 init: function(method, path, fn, options){45 this.method = method46 this.originalPath = path32 this.path = this.normalize(normalizePath(path))47 this.path = this.normalize(path)48 this.fn = fn49 },50 51 /**
33 unmodified lines
85 var self = this86 this.keys = []87 if (path instanceof RegExp) return path88 return new RegExp('^' + 74 escapeRegexp(path89 escapeRegexp(normalizePath(path)90 .replace(/\/:(\w+)\?/g, function(_, key){91 self.keys.push(key)92 return '(?:\/(.*?))?'93 })
111 unmodified lines
205 this.response.finish()206 }207})208194// --- Helpers195196/**197 * Normalize the given _path_.198 * Strips trailing slashes and whitespace.199 *200 * @param {string} path201 * @return {string}202 * @api private203 */204205function normalizePath(path) {206 return path.replace(/[\s\/]*$/g, '')207}208209// --- Express210211Express = { 212 version: '0.0.1',
5 unmodified lines