Added "case sensitive routes" option.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent d2f963d · Browse files · 5 files·+39 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+39 added−8 removed
- tests:+22 added−0 removed
- other:+17 added−8 removed
Provenance
- Commit
d2adcbd- Tree
dda4c55- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
d2f963d
5 files changed+39 added−8 removed
modified:docs/guide.md+1 added
81 unmodified lines82 * _views_ Root views directory defaulting to **CWD/views**83 * _view engine_ Default view engine name for views rendered without extensions84 * _view options_ An object specifying global view options85 * _view cache_ Enable view caching (enabled in production)86+ * _case sensitive routes_ Enable case-sensitive routing87 88 ### Routing89 90 Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.1252 unmodified linesmodified:lib/router/index.js+3 added-2 removed
32 unmodified lines33 * @return {Function}34 * @api private35 */36 37-function router(fn){37+function router(fn, app){38 var self = this39 , methods = {}40 , routes = {}41 , params = {};41 unmodified lines83 84 if (!path) throw new Error(name + ' route requires a path');85 if (!fn) throw new Error(name + ' route ' + path + ' requires a callback');86 87+ var options = { sensitive: app.enabled('case sensitive routes') };87- var route = new Route(name, path, fn);88+ var route = new Route(name, path, fn, options);89 localRoutes.push(route);90 return self;91 };92 }238 unmodified linesmodified:lib/router/route.js+12 added-5 removed
11 unmodified lines12131415161617181920212223242526272824293031322733343536376 unmodified lines4445464748495051524653545556578 unmodified lines6667686963707111 unmodified linesmodule.exports = Route;
/** * Initialize `Route` with the given HTTP `method`, `path`, * and callback `fn`. * and callback `fn` and `options`. * * Options: * * - `sensitive` enable case-sensitive routes * * @param {String} method * @param {String} path * @param {Function} fn * @param {Object} options. * @api private */
function Route(method, path, fn) {function Route(method, path, fn, options) { options = options || {}; this.callback = fn; this.path = path; this.regexp = normalize(path, this.keys = []); this.regexp = normalize(path, this.keys = [], options.sensitive); this.method = method;}
/**6 unmodified lines * then contain ["id"]. * * @param {String|RegExp} path * @param {Array} keys * @param {Boolean} sensitive * @return {RegExp} * @api private */
function normalize(path, keys) {function normalize(path, keys, sensitive) { if (path instanceof RegExp) return path; path = path .concat('/?') .replace(/\/\(/g, '(?:/')8 unmodified lines + (optional || ''); }) .replace(/([\/.])/g, '\\$1') .replace(/\*/g, '(.+)'); return new RegExp('^' + path + '$', 'i'); return new RegExp('^' + path + '$', sensitive ? '' : 'i');}No newline at end of fileNo newline at end of filemodified:lib/http.js+1 added-1 removed
85 unmodified lines86 // apply middleware87 if (middleware) middleware.forEach(self.use.bind(self));88 89 // use router, expose as app.get(), etc90- var fn = router(function(app){ self.routes = app; });90+ var fn = router(function(app){ self.routes = app; }, this);91 this.__defineGetter__('router', function(){92 this.__usedRouter = true;93 return fn;94 });409 unmodified linesmodified:test/router.test.js+22 added
239 unmodified lines240 app.match.get('/user/5/edit').should.have.length(2);241 app.match.get('/').should.have.be.empty;242 app.match.all('/user/123').should.have.length(3);243 app.match('/user/123').should.have.length(3);244+ },245+ 246+ 'test "case sensitive routes" setting': function(){247+ var app = express.createServer();248+249+ app.enable('case sensitive routes');250+251+ app.get('/account', function(req, res){252+ res.send('account');253+ });254+ 255+ app.get('/Account', function(req, res){256+ res.send('Account');257+ });258+259+ assert.response(app,260+ { url: '/account' },261+ { body: 'account' });262+263+ assert.response(app,264+ { url: '/Account' },265+ { body: 'Account' });266 }267 };