Skip to content

Commit

Permalink
Fix error in req.subdomains on empty host
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 9, 2014
1 parent 7d277c1 commit 70767b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
3.x
===

* Fix error in `req.subdomains` on empty host

3.17.0 / 2014-09-08
===================

Expand Down
3 changes: 3 additions & 0 deletions lib/request.js
Expand Up @@ -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()
Expand Down
22 changes: 11 additions & 11 deletions test/req.subdomains.js
Expand Up @@ -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){
Expand All @@ -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){
Expand All @@ -41,7 +41,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', '[::1]')
.expect([], done);
.expect(200, [], done);
})
})

Expand All @@ -56,7 +56,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'example.com')
.expect([], done);
.expect(200, [], done);
})
})

Expand All @@ -71,7 +71,7 @@ describe('req', function(){

request(app)
.get('/')
.expect([], done);
.expect(200, [], done);
})
})

Expand All @@ -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);
})
})

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -132,7 +132,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', '[::1]')
.expect(['[::1]'], done);
.expect(200, ['[::1]'], done);
})
})

Expand All @@ -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);
})
})

Expand All @@ -164,7 +164,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'sub.example.com')
.expect([], done);
.expect(200, [], done);
})
})
})
Expand Down

0 comments on commit 70767b1

Please sign in to comment.