| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d47dadc commit c9b05da
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + module.exports = { isLegalPort }; | ||
| 4 | + | ||
| 5 | + // Check that the port number is not NaN when coerced to a number, | ||
| 6 | + // is an integer and that it falls within the legal range of port numbers. | ||
| 7 | + function isLegalPort(port) { | ||
| 8 | + if (typeof port === 'string' && port.trim() === '') | ||
| 9 | + return false; | ||
| 10 | + return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF; | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const stream = require('stream'); | |||
| 5 | 5 | const timers = require('timers'); | |
| 6 | 6 | const util = require('util'); | |
| 7 | 7 | const internalUtil = require('internal/util'); | |
| 8 | + const internalNet = require('internal/net'); | ||
| 8 | 9 | const assert = require('assert'); | |
| 9 | 10 | const cares = process.binding('cares_wrap'); | |
| 10 | 11 | const uv = process.binding('uv'); | |
@@ -22,6 +23,7 @@ const WriteWrap = process.binding('stream_wrap').WriteWrap; | |||
| 22 | 23 | var cluster; | |
| 23 | 24 | const errnoException = util._errnoException; | |
| 24 | 25 | const exceptionWithHostPort = util._exceptionWithHostPort; | |
| 26 | + const isLegalPort = internalNet.isLegalPort; | ||
| 25 | 27 | ||
| 26 | 28 | function noop() {} | |
| 27 | 29 | ||
@@ -846,15 +848,6 @@ function connect(self, address, port, addressType, localAddress, localPort) { | |||
| 846 | 848 | } | |
| 847 | 849 | ||
| 848 | 850 | ||
| 849 | - // Check that the port number is not NaN when coerced to a number, | ||
| 850 | - // is an integer and that it falls within the legal range of port numbers. | ||
| 851 | - function isLegalPort(port) { | ||
| 852 | - if (typeof port === 'string' && port.trim() === '') | ||
| 853 | - return false; | ||
| 854 | - return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF; | ||
| 855 | - } | ||
| 856 | - | ||
| 857 | - | ||
| 858 | 851 | Socket.prototype.connect = function(options, cb) { | |
| 859 | 852 | if (this.write !== Socket.prototype.write) | |
| 860 | 853 | this.write = Socket.prototype.write; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,6 +74,7 @@ | |||
| 74 | 74 | 'lib/internal/cluster.js', | |
| 75 | 75 | 'lib/internal/freelist.js', | |
| 76 | 76 | 'lib/internal/linkedlist.js', | |
| 77 | + 'lib/internal/net.js', | ||
| 77 | 78 | 'lib/internal/module.js', | |
| 78 | 79 | 'lib/internal/repl.js', | |
| 79 | 80 | 'lib/internal/socket_list.js', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --expose-internals | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const net = require('internal/net'); | ||
| 8 | + | ||
| 9 | + assert.strictEqual(net.isLegalPort(''), false); | ||
| 10 | + assert.strictEqual(net.isLegalPort('0'), true); | ||
| 11 | + assert.strictEqual(net.isLegalPort(0), true); | ||
| 12 | + assert.strictEqual(net.isLegalPort(65536), false); | ||
| 13 | + assert.strictEqual(net.isLegalPort('65535'), true); | ||
| 14 | + assert.strictEqual(net.isLegalPort(undefined), false); | ||
| 15 | + assert.strictEqual(net.isLegalPort(null), true); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments