fix: subdomains should be [] if the host is an ip (#807)
* fix: subdomains should be [] if the host is an ip Fixes #775
This commit is contained in:
parent
1aa85ce721
commit
b1a14f1a73
2 changed files with 11 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var net = require('net');
|
||||||
var contentType = require('content-type');
|
var contentType = require('content-type');
|
||||||
var stringify = require('url').format;
|
var stringify = require('url').format;
|
||||||
var parse = require('parseurl');
|
var parse = require('parseurl');
|
||||||
|
@ -417,7 +418,9 @@ module.exports = {
|
||||||
|
|
||||||
get subdomains() {
|
get subdomains() {
|
||||||
var offset = this.app.subdomainOffset;
|
var offset = this.app.subdomainOffset;
|
||||||
return (this.host || '')
|
var host = this.host || '';
|
||||||
|
if (net.isIP(host)) return [];
|
||||||
|
return host
|
||||||
.split('.')
|
.split('.')
|
||||||
.reverse()
|
.reverse()
|
||||||
.slice(offset);
|
.slice(offset);
|
||||||
|
|
|
@ -14,8 +14,14 @@ describe('req.subdomains', function(){
|
||||||
req.subdomains.should.eql(['tobi']);
|
req.subdomains.should.eql(['tobi']);
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with no host present', function(){
|
it('should work with no host present', function(){
|
||||||
var req = request();
|
var req = request();
|
||||||
req.subdomains.should.eql([]);
|
req.subdomains.should.eql([]);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should check if the host is an ip address', function(){
|
||||||
|
var req = request();
|
||||||
|
req.header.host = '127.0.0.1';
|
||||||
|
req.subdomains.should.eql([]);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue