Browse Source

dns: verify argument is valid function in resolve

Don't use argument as callback if it's not a valid callback function.
Throw a valid exception instead explaining the issue.

Adds to #7070 ("DNS — Throw meaningful error(s)").
v0.11.12-release
Kenan Sulayman 11 years ago
committed by Fedor Indutny
parent
commit
abe4c34c86
  1. 4
      lib/dns.js
  2. 10
      test/simple/test-dns.js

4
lib/dns.js

@ -185,9 +185,11 @@ exports.resolve = function(hostname, type_, callback_) {
if (util.isString(type_)) { if (util.isString(type_)) {
resolver = resolveMap[type_]; resolver = resolveMap[type_];
callback = callback_; callback = callback_;
} else { } else if (util.isFunction(type_)) {
resolver = exports.resolve4; resolver = exports.resolve4;
callback = type_; callback = type_;
} else {
throw new Error('Type must be a string');
} }
if (util.isFunction(resolver)) { if (util.isFunction(resolver)) {

10
test/simple/test-dns.js

@ -60,3 +60,13 @@ assert.deepEqual(dns.getServers(), portsExpected);
assert.doesNotThrow(function () { dns.setServers([]); }); assert.doesNotThrow(function () { dns.setServers([]); });
assert.deepEqual(dns.getServers(), []); assert.deepEqual(dns.getServers(), []);
assert.throws(
function() {
dns.resolve('test.com', [], new Function);
},
function(err) {
return !(err instanceof TypeError);
},
"Unexpected error"
);

Loading…
Cancel
Save