-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: move isLegalPort to internal/net
isLegalPort can be used in more places than just net.js. This change moves it to a new internal net module in preparation for using it in the dns module. PR-URL: #4882 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
- Loading branch information
Showing
4 changed files
with
29 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'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 === 'string' && port.trim() === '') | ||
return false; | ||
return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// Flags: --expose-internals | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const net = require('internal/net'); | ||
|
||
assert.strictEqual(net.isLegalPort(''), false); | ||
assert.strictEqual(net.isLegalPort('0'), true); | ||
assert.strictEqual(net.isLegalPort(0), true); | ||
assert.strictEqual(net.isLegalPort(65536), false); | ||
assert.strictEqual(net.isLegalPort('65535'), true); | ||
assert.strictEqual(net.isLegalPort(undefined), false); | ||
assert.strictEqual(net.isLegalPort(null), true); |