Fix error in req.subdomains on empty host
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7d277c1 · Browse files · 3 files·+19 added−11 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+19 added−11 removed
- tests:+11 added−11 removed
- other:+8 added−0 removed
Provenance
- Commit
70767b1- Tree
5cb0188- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
7d277c1
3 files changed+19 added−11 removed
modified:lib/request.js+3 added
452 unmodified lines453 */454 455 req.__defineGetter__('subdomains', function(){456 var host = this.host;457+458+ if (!host) return [];459+460 var offset = this.app.get('subdomain offset');461 var subdomains = !isIP(host)462 ? host.split('.').reverse()463 : [host];95 unmodified linesmodified:test/req.subdomains.js+11 added-11 removed
13 unmodified lines141516171818192021224 unmodified lines272829303131323334354 unmodified lines404142434444454647486 unmodified lines555657585959606162636 unmodified lines707172737474757677787 unmodified lines868788899090919293948 unmodified lines1031041051061071071081091101115 unmodified lines1171181191201211211221231241255 unmodified lines1311321331341351351361371381397 unmodified lines1471481491501511511521531541557 unmodified lines16316416516616716716816917017117213 unmodified lines
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){ var app = express();4 unmodified lines
request(app) .get('/') .set('Host', '127.0.0.1') .expect([], done); .expect(200, [], done); })
it('should work with IPv6 address', function(done){ var app = express();4 unmodified lines
request(app) .get('/') .set('Host', '[::1]') .expect([], done); .expect(200, [], done); }) })
describe('otherwise', function(){6 unmodified lines
request(app) .get('/') .set('Host', 'example.com') .expect([], done); .expect(200, [], done); }) })
describe('with no host', function(){6 unmodified lines });
request(app) .get('/') .expect([], done); .expect(200, [], done); }) })
describe('with trusted X-Forwarded-Host', function () {7 unmodified lines
request(app) .get('/') .set('X-Forwarded-Host', 'tobi.ferrets.example.com') .expect(['ferrets', 'tobi'], done); .expect(200, ['ferrets', 'tobi'], done); }) })
describe('when subdomain offset is set', function(){8 unmodified lines
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) { var app = express();5 unmodified lines
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) { var app = express();5 unmodified lines
request(app) .get('/') .set('Host', '[::1]') .expect(['[::1]'], done); .expect(200, ['[::1]'], done); }) })
describe('when present', function(){7 unmodified lines
request(app) .get('/') .set('Host', 'tobi.ferrets.sub.example.com') .expect(["ferrets","tobi"], done); .expect(200, ['ferrets', 'tobi'], done); }) })
describe('otherwise', function(){7 unmodified lines
request(app) .get('/') .set('Host', 'sub.example.com') .expect([], done); .expect(200, [], done); }) }) }) })})modified:History.md+5 added
1+3.x2+===3+4+ * Fix error in `req.subdomains` on empty host5+6 3.17.0 / 2014-09-087 ===================8 9 * Support IP address host in `req.subdomains`1745 unmodified lines