From 70767b19aca926faf679d6ccdd068ba98c52d480 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 8 Sep 2014 23:45:34 -0400 Subject: [PATCH] Fix error in req.subdomains on empty host --- History.md | 5 +++++ lib/request.js | 3 +++ test/req.subdomains.js | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/History.md b/History.md index 739302555e..e4f2e7bc4b 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +3.x +=== + + * Fix error in `req.subdomains` on empty host + 3.17.0 / 2014-09-08 =================== diff --git a/lib/request.js b/lib/request.js index 24e8748d21..683d54805c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -454,6 +454,9 @@ req.__defineGetter__('auth', function(){ req.__defineGetter__('subdomains', function(){ var host = this.host; + + if (!host) return []; + var offset = this.app.get('subdomain offset'); var subdomains = !isIP(host) ? host.split('.').reverse() diff --git a/test/req.subdomains.js b/test/req.subdomains.js index 7da382f478..18e4d80ad3 100644 --- a/test/req.subdomains.js +++ b/test/req.subdomains.js @@ -15,7 +15,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', 'tobi.ferrets.example.com') - .expect(["ferrets","tobi"], done); + .expect(200, ['ferrets', 'tobi'], done); }) it('should work with IPv4 address', function(done){ @@ -28,7 +28,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', '127.0.0.1') - .expect([], done); + .expect(200, [], done); }) it('should work with IPv6 address', function(done){ @@ -41,7 +41,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', '[::1]') - .expect([], done); + .expect(200, [], done); }) }) @@ -56,7 +56,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', 'example.com') - .expect([], done); + .expect(200, [], done); }) }) @@ -71,7 +71,7 @@ describe('req', function(){ request(app) .get('/') - .expect([], done); + .expect(200, [], done); }) }) @@ -87,7 +87,7 @@ describe('req', function(){ request(app) .get('/') .set('X-Forwarded-Host', 'tobi.ferrets.example.com') - .expect(['ferrets', 'tobi'], done); + .expect(200, ['ferrets', 'tobi'], done); }) }) @@ -104,7 +104,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', 'tobi.ferrets.sub.example.com') - .expect(["com","example","sub","ferrets","tobi"], done); + .expect(200, ['com', 'example', 'sub', 'ferrets', 'tobi'], done); }) it('should return an array with the whole IPv4', function (done) { @@ -118,7 +118,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', '127.0.0.1') - .expect(['127.0.0.1'], done); + .expect(200, ['127.0.0.1'], done); }) it('should return an array with the whole IPv6', function (done) { @@ -132,7 +132,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', '[::1]') - .expect(['[::1]'], done); + .expect(200, ['[::1]'], done); }) }) @@ -148,7 +148,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', 'tobi.ferrets.sub.example.com') - .expect(["ferrets","tobi"], done); + .expect(200, ['ferrets', 'tobi'], done); }) }) @@ -164,7 +164,7 @@ describe('req', function(){ request(app) .get('/') .set('Host', 'sub.example.com') - .expect([], done); + .expect(200, [], done); }) }) })