dns: fix inconsistent (hostname vs host)
Fixes: https://github.com/nodejs/node/issues/20892 PR-URL: https://github.com/nodejs/node/pull/23572 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
6c5e97f2f0
commit
beb0f03e78
20
lib/dns.js
20
lib/dns.js
@ -152,21 +152,21 @@ Object.defineProperty(lookup, customPromisifyArgs,
|
||||
{ value: ['address', 'family'], enumerable: false });
|
||||
|
||||
|
||||
function onlookupservice(err, host, service) {
|
||||
function onlookupservice(err, hostname, service) {
|
||||
if (err)
|
||||
return this.callback(dnsException(err, 'getnameinfo', this.host));
|
||||
return this.callback(dnsException(err, 'getnameinfo', this.hostname));
|
||||
|
||||
this.callback(null, host, service);
|
||||
this.callback(null, hostname, service);
|
||||
}
|
||||
|
||||
|
||||
// lookupService(address, port, callback)
|
||||
function lookupService(host, port, callback) {
|
||||
function lookupService(hostname, port, callback) {
|
||||
if (arguments.length !== 3)
|
||||
throw new ERR_MISSING_ARGS('host', 'port', 'callback');
|
||||
throw new ERR_MISSING_ARGS('hostname', 'port', 'callback');
|
||||
|
||||
if (isIP(host) === 0)
|
||||
throw new ERR_INVALID_OPT_VALUE('host', host);
|
||||
if (isIP(hostname) === 0)
|
||||
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);
|
||||
|
||||
if (!isLegalPort(port))
|
||||
throw new ERR_SOCKET_BAD_PORT(port);
|
||||
@ -178,12 +178,12 @@ function lookupService(host, port, callback) {
|
||||
|
||||
var req = new GetNameInfoReqWrap();
|
||||
req.callback = callback;
|
||||
req.host = host;
|
||||
req.hostname = hostname;
|
||||
req.port = port;
|
||||
req.oncomplete = onlookupservice;
|
||||
|
||||
var err = cares.getnameinfo(req, host, port);
|
||||
if (err) throw dnsException(err, 'getnameinfo', host);
|
||||
var err = cares.getnameinfo(req, hostname, port);
|
||||
if (err) throw dnsException(err, 'getnameinfo', hostname);
|
||||
return req;
|
||||
}
|
||||
|
||||
|
@ -129,34 +129,34 @@ function onlookupservice(err, hostname, service) {
|
||||
this.resolve({ hostname, service });
|
||||
}
|
||||
|
||||
function createLookupServicePromise(host, port) {
|
||||
function createLookupServicePromise(hostname, port) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = new GetNameInfoReqWrap();
|
||||
|
||||
req.host = host;
|
||||
req.hostname = hostname;
|
||||
req.port = port;
|
||||
req.oncomplete = onlookupservice;
|
||||
req.resolve = resolve;
|
||||
req.reject = reject;
|
||||
|
||||
const err = getnameinfo(req, host, port);
|
||||
const err = getnameinfo(req, hostname, port);
|
||||
|
||||
if (err)
|
||||
reject(dnsException(err, 'getnameinfo', host));
|
||||
reject(dnsException(err, 'getnameinfo', hostname));
|
||||
});
|
||||
}
|
||||
|
||||
function lookupService(host, port) {
|
||||
function lookupService(hostname, port) {
|
||||
if (arguments.length !== 2)
|
||||
throw new ERR_MISSING_ARGS('host', 'port');
|
||||
throw new ERR_MISSING_ARGS('hostname', 'port');
|
||||
|
||||
if (isIP(host) === 0)
|
||||
throw new ERR_INVALID_OPT_VALUE('host', host);
|
||||
if (isIP(hostname) === 0)
|
||||
throw new ERR_INVALID_OPT_VALUE('hostname', hostname);
|
||||
|
||||
if (!isLegalPort(port))
|
||||
throw new ERR_SOCKET_BAD_PORT(port);
|
||||
|
||||
return createLookupServicePromise(host, +port);
|
||||
return createLookupServicePromise(hostname, +port);
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,12 +291,12 @@ const mockedErrorCode = 'ENOTFOUND';
|
||||
const mockedSysCall = 'getaddrinfo';
|
||||
|
||||
function errorLookupMock(code = mockedErrorCode, syscall = mockedSysCall) {
|
||||
return function lookupWithError(host, dnsopts, cb) {
|
||||
const err = new Error(`${syscall} ${code} ${host}`);
|
||||
return function lookupWithError(hostname, dnsopts, cb) {
|
||||
const err = new Error(`${syscall} ${code} ${hostname}`);
|
||||
err.code = code;
|
||||
err.errno = code;
|
||||
err.syscall = syscall;
|
||||
err.hostname = host;
|
||||
err.hostname = hostname;
|
||||
cb(err);
|
||||
};
|
||||
}
|
||||
|
@ -261,11 +261,12 @@ dns.lookup('', {
|
||||
const err = {
|
||||
code: 'ERR_MISSING_ARGS',
|
||||
type: TypeError,
|
||||
message: 'The "host", "port", and "callback" arguments must be specified'
|
||||
message: 'The "hostname", "port", and "callback" arguments must be ' +
|
||||
'specified'
|
||||
};
|
||||
|
||||
common.expectsError(() => dns.lookupService('0.0.0.0'), err);
|
||||
err.message = 'The "host" and "port" arguments must be specified';
|
||||
err.message = 'The "hostname" and "port" arguments must be specified';
|
||||
common.expectsError(() => dnsPromises.lookupService('0.0.0.0'), err);
|
||||
}
|
||||
|
||||
@ -274,7 +275,7 @@ dns.lookup('', {
|
||||
const err = {
|
||||
code: 'ERR_INVALID_OPT_VALUE',
|
||||
type: TypeError,
|
||||
message: `The value "${invalidHost}" is invalid for option "host"`
|
||||
message: `The value "${invalidHost}" is invalid for option "hostname"`
|
||||
};
|
||||
|
||||
common.expectsError(() => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user