diff options
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/net.js b/lib/net.js index 2b0afa578..cef0475fa 100644 --- a/lib/net.js +++ b/lib/net.js @@ -895,7 +895,7 @@ Socket.prototype.connect = function(options, cb) { } else { var dns = require('dns'); var host = options.host || 'localhost'; - var port = options.port | 0; + var port = 0; var localAddress = options.localAddress; var localPort = options.localPort; var dnsopts = { @@ -909,8 +909,16 @@ Socket.prototype.connect = function(options, cb) { if (localPort && !util.isNumber(localPort)) throw new TypeError('localPort should be a number: ' + localPort); - if (port <= 0 || port > 65535) - throw new RangeError('port should be > 0 and < 65536: ' + port); + if (typeof options.port === 'number') + port = options.port; + else if (typeof options.port === 'string') + port = options.port.trim() === '' ? -1 : +options.port; + else if (options.port !== undefined) + throw new TypeError('port should be a number or string: ' + options.port); + + if (port < 0 || port > 65535 || isNaN(port)) + throw new RangeError('port should be >= 0 and < 65536: ' + + options.port); if (dnsopts.family !== 4 && dnsopts.family !== 6) dnsopts.hints = dns.ADDRCONFIG | dns.V4MAPPED; |