Skip to content
Myr

Fix case where router.use skipped requests routes did not

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

fixes #3037

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 8b6dc6c · Browse files · 3 files+43 added−5 removed
This commit

State

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

Diff stats

3 files+43 added−5 removed

  • tests:+36 added−0 removed
  • other:+7 added−5 removed

3 files+43 added−5 removed

modified:lib/router/index.js+6 added-5 removed
278 unmodified lines
279 });280 }281282 function trim_prefix(layer, layerError, layerPath, path) {283 var c = path[layerPath.length];284 if (c && '/' !== c && '.' !== c) return next(layerError);285286 // Trim off the part of the url that matches the route287 // middleware (.use stuff) needs to have the path stripped283 if (layerPath.length !== 0) {284 // Validate path breaks on a path separator285 var c = path[layerPath.length]286 if (c && c !== '/' && c !== '.') return next(layerError)287288 // Trim off the part of the url that matches the route289 // middleware (.use stuff) needs to have the path stripped290 debug('trim prefix (%s) from url %s', layerPath, req.url);291 removed = layerPath;292 req.url = protohost + req.url.substr(protohost.length + removed.length);293
363 unmodified lines
modified:test/Router.js+36 added
345 unmodified lines
346347 assert.equal(count, methods.length);348 done();349 })350351 it('should be called for any URL when "*"', function (done) {352 var cb = after(4, done)353 var router = new Router()354355 function no () {356 throw new Error('should not be called')357 }358359 router.all('*', function (req, res) {360 res.end()361 })362363 router.handle({ url: '/', method: 'GET' }, { end: cb }, no)364 router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)365 router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)366 router.handle({ url: '*', method: 'GET' }, { end: cb }, no)367 })368 })369370 describe('.use', function() {371 it('should require arguments', function(){
8 unmodified lines
380 router.use.bind(router, '/', null).should.throw(/requires middleware function.*Null/)381 router.use.bind(router, '/', new Date()).should.throw(/requires middleware function.*Date/)382 })383384 it('should be called for any URL', function (done) {385 var cb = after(4, done)386 var router = new Router()387388 function no () {389 throw new Error('should not be called')390 }391392 router.use(function (req, res) {393 res.end()394 })395396 router.handle({ url: '/', method: 'GET' }, { end: cb }, no)397 router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)398 router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)399 router.handle({ url: '*', method: 'GET' }, { end: cb }, no)400 })401402 it('should accept array of middleware', function(done){403 var count = 0;404 var router = new Router();405
146 unmodified lines
modified:History.md+1 added
1unreleased2==========34 * Add debug message when loading view engine5 * Fix case where `router.use` skipped requests routes did not6 * Remove usage of `res._headers` private field7 - Improves compatibility with Node.js 8 nightly8 * Skip routing when `req.url` is not set9 * Use `%o` in path debug to tell types apart
3222 unmodified lines