dns: throw if hostname is not string or falsey
Fix assertion failure from poor argument parsing logic introduced in 6ea5d16. Add tests to make sure arguments are properly parsed. Fixes: 6ea5d16 "dns: always set variable family in lookup()" Reviewed-by: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
437c2f4383
commit
5086d6ef94
@ -105,7 +105,9 @@ exports.lookup = function lookup(hostname, options, callback) {
|
|||||||
var family = -1;
|
var family = -1;
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
if (typeof options === 'function') {
|
if (hostname && typeof hostname !== 'string') {
|
||||||
|
throw TypeError('invalid arguments: hostname must be a string or falsey');
|
||||||
|
} else if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
family = 0;
|
family = 0;
|
||||||
} else if (typeof callback !== 'function') {
|
} else if (typeof callback !== 'function') {
|
||||||
|
@ -69,6 +69,47 @@ assert.throws(function() {
|
|||||||
return !(err instanceof TypeError);
|
return !(err instanceof TypeError);
|
||||||
}, 'Unexpected error');
|
}, 'Unexpected error');
|
||||||
|
|
||||||
|
// dns.lookup should accept falsey and string values
|
||||||
|
assert.throws(function() {
|
||||||
|
dns.lookup({}, noop);
|
||||||
|
}, 'invalid arguments: hostname must be a string or falsey');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
dns.lookup([], noop);
|
||||||
|
}, 'invalid arguments: hostname must be a string or falsey');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
dns.lookup(true, noop);
|
||||||
|
}, 'invalid arguments: hostname must be a string or falsey');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
dns.lookup(1, noop);
|
||||||
|
}, 'invalid arguments: hostname must be a string or falsey');
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
dns.lookup(noop, noop);
|
||||||
|
}, 'invalid arguments: hostname must be a string or falsey');
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
dns.lookup('', noop);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
dns.lookup(null, noop);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
dns.lookup(undefined, noop);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
dns.lookup(0, noop);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
dns.lookup(NaN, noop);
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure that dns.lookup throws if hints does not represent a valid flag.
|
* Make sure that dns.lookup throws if hints does not represent a valid flag.
|
||||||
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
|
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user