diff options
author | Julien Gilli <julien.gilli@joyent.com> | 2015-03-16 15:55:17 -0700 |
---|---|---|
committer | Julien Gilli <julien.gilli@joyent.com> | 2015-03-16 15:55:17 -0700 |
commit | ae58fc407f916b2abb164453a5b09273c543dbc3 (patch) | |
tree | 4a16fe73f996a54f34cfb553b2995d16c1375b7f /lib/net.js | |
parent | 2b64132101f179c30957e3c5f16fc47a8ec942e1 (diff) | |
parent | eb2764a9452baa7cba2d98dc34fa00fc776b0a12 (diff) | |
download | node-merge-review.tar.gz |
Merge remote-tracking branch 'upstream/v0.12'merge-review
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; |