dns: cleanup validation

The `validateString()` validator should cleanup the validation and
keep consistency.

PR-URL: https://github.com/nodejs/node/pull/40061
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Voltrex 2021-09-10 08:49:58 +04:30 committed by Node.js GitHub Bot
parent de10ab25d3
commit eb44d19a18
1 changed files with 2 additions and 3 deletions

View File

@ -32,7 +32,6 @@ const IPv6RE = /^\[([^[\]]*)\]/;
const addrSplitRE = /(^.+?)(?::(\d+))?$/;
const {
ERR_DNS_SET_SERVERS_FAILED,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_IP_ADDRESS,
} = errors.codes;
@ -131,8 +130,8 @@ class Resolver {
setLocalAddress(ipv4, ipv6) {
validateString(ipv4, 'ipv4');
if (typeof ipv6 !== 'string' && ipv6 !== undefined) {
throw new ERR_INVALID_ARG_TYPE('ipv6', ['String', 'undefined'], ipv6);
if (ipv6 !== undefined) {
validateString(ipv6, 'ipv6');
}
this._handle.setLocalAddress(ipv4, ipv6);