Skip to content

Commit 70767b1

Browse files
committed
Fix error in req.subdomains on empty host
1 parent 7d277c1 commit 70767b1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Diff for: History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
3.x
2+
===
3+
4+
* Fix error in `req.subdomains` on empty host
5+
16
3.17.0 / 2014-09-08
27
===================
38

Diff for: lib/request.js

+3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ req.__defineGetter__('auth', function(){
454454

455455
req.__defineGetter__('subdomains', function(){
456456
var host = this.host;
457+
458+
if (!host) return [];
459+
457460
var offset = this.app.get('subdomain offset');
458461
var subdomains = !isIP(host)
459462
? host.split('.').reverse()

Diff for: test/req.subdomains.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('req', function(){
1515
request(app)
1616
.get('/')
1717
.set('Host', 'tobi.ferrets.example.com')
18-
.expect(["ferrets","tobi"], done);
18+
.expect(200, ['ferrets', 'tobi'], done);
1919
})
2020

2121
it('should work with IPv4 address', function(done){
@@ -28,7 +28,7 @@ describe('req', function(){
2828
request(app)
2929
.get('/')
3030
.set('Host', '127.0.0.1')
31-
.expect([], done);
31+
.expect(200, [], done);
3232
})
3333

3434
it('should work with IPv6 address', function(done){
@@ -41,7 +41,7 @@ describe('req', function(){
4141
request(app)
4242
.get('/')
4343
.set('Host', '[::1]')
44-
.expect([], done);
44+
.expect(200, [], done);
4545
})
4646
})
4747

@@ -56,7 +56,7 @@ describe('req', function(){
5656
request(app)
5757
.get('/')
5858
.set('Host', 'example.com')
59-
.expect([], done);
59+
.expect(200, [], done);
6060
})
6161
})
6262

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

7272
request(app)
7373
.get('/')
74-
.expect([], done);
74+
.expect(200, [], done);
7575
})
7676
})
7777

@@ -87,7 +87,7 @@ describe('req', function(){
8787
request(app)
8888
.get('/')
8989
.set('X-Forwarded-Host', 'tobi.ferrets.example.com')
90-
.expect(['ferrets', 'tobi'], done);
90+
.expect(200, ['ferrets', 'tobi'], done);
9191
})
9292
})
9393

@@ -104,7 +104,7 @@ describe('req', function(){
104104
request(app)
105105
.get('/')
106106
.set('Host', 'tobi.ferrets.sub.example.com')
107-
.expect(["com","example","sub","ferrets","tobi"], done);
107+
.expect(200, ['com', 'example', 'sub', 'ferrets', 'tobi'], done);
108108
})
109109

110110
it('should return an array with the whole IPv4', function (done) {
@@ -118,7 +118,7 @@ describe('req', function(){
118118
request(app)
119119
.get('/')
120120
.set('Host', '127.0.0.1')
121-
.expect(['127.0.0.1'], done);
121+
.expect(200, ['127.0.0.1'], done);
122122
})
123123

124124
it('should return an array with the whole IPv6', function (done) {
@@ -132,7 +132,7 @@ describe('req', function(){
132132
request(app)
133133
.get('/')
134134
.set('Host', '[::1]')
135-
.expect(['[::1]'], done);
135+
.expect(200, ['[::1]'], done);
136136
})
137137
})
138138

@@ -148,7 +148,7 @@ describe('req', function(){
148148
request(app)
149149
.get('/')
150150
.set('Host', 'tobi.ferrets.sub.example.com')
151-
.expect(["ferrets","tobi"], done);
151+
.expect(200, ['ferrets', 'tobi'], done);
152152
})
153153
})
154154

@@ -164,7 +164,7 @@ describe('req', function(){
164164
request(app)
165165
.get('/')
166166
.set('Host', 'sub.example.com')
167-
.expect([], done);
167+
.expect(200, [], done);
168168
})
169169
})
170170
})

0 commit comments

Comments
 (0)