lib: fix validateport error message when allowZero is false
PR-URL: https://github.com/nodejs/node/pull/32861 Fixes: https://github.com/nodejs/node/issues/32857 Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
aa9708e479
commit
1d0b24924f
@ -1318,8 +1318,12 @@ E('ERR_SERVER_NOT_RUNNING', 'Server is not running.', Error);
|
||||
E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound', Error);
|
||||
E('ERR_SOCKET_BAD_BUFFER_SIZE',
|
||||
'Buffer size must be a positive integer', TypeError);
|
||||
E('ERR_SOCKET_BAD_PORT',
|
||||
'%s should be >= 0 and < 65536. Received %s.', RangeError);
|
||||
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}.`;
|
||||
}, RangeError);
|
||||
E('ERR_SOCKET_BAD_TYPE',
|
||||
'Bad socket type specified. Valid types are: udp4, udp6', TypeError);
|
||||
E('ERR_SOCKET_BUFFER_SIZE',
|
||||
|
@ -190,7 +190,7 @@ function validatePort(port, name = 'Port', { allowZero = true } = {}) {
|
||||
+port !== (+port >>> 0) ||
|
||||
port > 0xFFFF ||
|
||||
(port === 0 && !allowZero)) {
|
||||
throw new ERR_SOCKET_BAD_PORT(name, port);
|
||||
throw new ERR_SOCKET_BAD_PORT(name, port, allowZero);
|
||||
}
|
||||
return port | 0;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ assert.throws(() => {
|
||||
client.connect(port);
|
||||
}, {
|
||||
name: 'RangeError',
|
||||
message: /^Port should be >= 0 and < 65536/,
|
||||
message: /^Port should be > 0 and < 65536/,
|
||||
code: 'ERR_SOCKET_BAD_PORT'
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user