Skip to content
Myr

Support non-string path in app.use(path, fn)

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

fixes #2207

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 4ea6f21 · Browse files · 5 files+69 added−21 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+69 added−21 removed

  • tests:+46 added−0 removed
  • other:+23 added−21 removed

5 files+69 added−21 removed

modified:lib/router/index.js+8 added-13 removed
383 unmodified lines
384 * @return {app} for chaining385 * @api public386 */387388proto.use = function(route, fn){389 // default route to '/'390 if ('string' != typeof route) {391 fn = route;392 route = '/';388proto.use = function(path, fn){389 // default path to '/'390 if (arguments.length < 2) {391 fn = path;392 path = '/';393 }394395 if (typeof fn !== 'function') {396 var type = {}.toString.call(fn);397 var msg = 'Router.use() requires callback functions but got a ' + type;398 throw new Error(msg);399 }400401 // strip trailing slash402 if ('/' == route[route.length - 1]) {403 route = route.slice(0, -1);404 }405406 var layer = new Layer(route, {401 var layer = new Layer(path, {402 sensitive: this.caseSensitive,408 strict: this.strict,403 strict: false,404 end: false405 }, fn);406407 // add the middleware413 debug('use %s %s', route || '/', fn.name || 'anonymous');408 debug('use %s %s', path || '/', fn.name || 'anonymous');409410 this.stack.push(layer);411 return this;412};
101 unmodified lines
modified:lib/application.js+9 added-6 removed
145 unmodified lines
146 *147 * @api public148 */149150app.use = function(route, fn){150app.use = function use(path, fn){151 var mount_app;152153 // default route to '/'154 if ('string' != typeof route) fn = route, route = '/';153 // default path to '/'154 if (arguments.length < 2) {155 fn = path;156 path = '/';157 }158159 // express app160 if (fn.handle && fn.set) mount_app = fn;161162 // restore .app property on req and res163 if (mount_app) {161 debug('.use app under %s', route);162 mount_app.mountpath = route;164 debug('.use app under %s', path);165 mount_app.mountpath = path;166 fn = function(req, res, next) {167 var orig = req.app;168 mount_app.handle(req, res, function(err) {169 req.__proto__ = orig.request;
3 unmodified lines
173 };174 }175176 this.lazyrouter();174 this._router.use(route, fn);177 this._router.use(path, fn);178179 // mounted an app180 if (mount_app) {181 mount_app.parent = this;
359 unmodified lines
modified:test/app.use.js+46 added
modified:History.md+4 added
4 unmodified lines
5 - previous versions are not vulnerable; this is just explicit protection6 * deprecate `res.redirect(url, status)` -- use `res.redirect(status, url)` instead7 * fix `res.send(status, num)` to send `num` as json (not error)8 * remove unnecessary escaping when `res.jsonp` returns JSON response9 * support non-string `path` in `app.use(path, fn)`10 - supports array of paths11 - supports `RegExp`12 * deps: debug@1.0.313 - Add support for multiple wildcards in namespaces14 * deps: methods@1.1.015 - add `CONNECT`16 * deps: parseurl@~1.1.317 - faster parsing of href-only URLs18 * deps: path-to-regexp@0.1.319204.5.1 / 2014-07-0621==================22
1768 unmodified lines
modified:package.json+2 added-2 removed
32 unmodified lines
33 "finalhandler": "0.0.2",34 "media-typer": "0.2.0",35 "methods": "1.1.0",36 "parseurl": "~1.1.3",37 "path-to-regexp": "0.1.3",38 "proxy-addr": "1.0.1",39 "range-parser": "1.0.0",40 "send": "0.5.0",41 "serve-static": "~1.3.0",
2 unmodified lines
44 "cookie": "0.1.2",45 "fresh": "0.2.2",46 "cookie-signature": "1.0.4",47 "merge-descriptors": "0.0.2",47 "utils-merge": "1.0.0",48 "qs": "0.6.6",49 "path-to-regexp": "0.1.2"49 "utils-merge": "1.0.0"50 },51 "devDependencies": {52 "after": "0.8.1",53 "istanbul": "0.3.0",
26 unmodified lines