mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Add stricter testing for the isLegalPort method in internal/net. This ensures that odd inputs such as isLegalPort(true) and isLegalPort([1]) aren't acceptable as valid port inputs. PR-URL: https://github.com/nodejs/node/pull/5733 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
13 lines
419 B
JavaScript
13 lines
419 B
JavaScript
'use strict';
|
|
|
|
module.exports = { isLegalPort };
|
|
|
|
// Check that the port number is not NaN when coerced to a number,
|
|
// is an integer and that it falls within the legal range of port numbers.
|
|
function isLegalPort(port) {
|
|
if ((typeof port !== 'number' && typeof port !== 'string') ||
|
|
(typeof port === 'string' && port.trim().length === 0))
|
|
return false;
|
|
return +port === (+port >>> 0) && port <= 0xFFFF;
|
|
}
|