Skip to content

Commit

Permalink
dns: fix port validation
Browse files Browse the repository at this point in the history
Previously the error message generation would throw if the port was of
type `"symbol"`.

PR-URL: #45135
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
aduh95 authored and danielleadams committed Jan 3, 2023
1 parent a534175 commit 9ceed7a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/internal/errors.js
Expand Up @@ -1569,7 +1569,7 @@ E('ERR_SOCKET_BAD_PORT', (name, port, allowZero = true) => {
assert(typeof allowZero === 'boolean',
"The 'allowZero' argument must be of type boolean.");
const operator = allowZero ? '>=' : '>';
return `${name} should be ${operator} 0 and < 65536. Received ${port}.`;
return `${name} should be ${operator} 0 and < 65536. Received ${determineSpecificType(port)}.`;
}, RangeError);
E('ERR_SOCKET_BAD_TYPE',
'Bad socket type specified. Valid types are: udp4, udp6', TypeError);
Expand Down
7 changes: 1 addition & 6 deletions test/parallel/test-dns.js
Expand Up @@ -310,8 +310,6 @@ dns.lookup('', {
const portErr = (port) => {
const err = {
code: 'ERR_SOCKET_BAD_PORT',
message:
`Port should be >= 0 and < 65536. Received ${port}.`,
name: 'RangeError'
};

Expand All @@ -323,10 +321,7 @@ const portErr = (port) => {
dns.lookupService('0.0.0.0', port, common.mustNotCall());
}, err);
};
portErr(null);
portErr(undefined);
portErr(65538);
portErr('test');
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach(portErr);

assert.throws(() => {
dns.lookupService('0.0.0.0', 80, null);
Expand Down

0 comments on commit 9ceed7a

Please sign in to comment.