From 1d28cfcfb9ad48e03a0b6c48eda97b5c91a5e3ae Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 9 May 2010 12:10:38 -0700 Subject: [PATCH] Better logic for testing if an argument is a port If you did server.listen('123') it would open a socket in the current directory called 123. Now it will interpret it as a port. --- lib/net.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net.js b/lib/net.js index 5849401..1daf841 100644 --- a/lib/net.js +++ b/lib/net.js @@ -759,6 +759,8 @@ function doConnect (socket, port, host) { }; } +function isPort (x) { return parseInt(x) >= 0; } + // var stream = new Stream(); // stream.connect(80) - TCP connect to port 80 on the localhost @@ -774,7 +776,7 @@ Stream.prototype.connect = function () { self._connecting = true; // set false in doConnect - if (parseInt(arguments[0]) >= 0) { + if (isPort(arguments[0])) { // TCP var port = arguments[0]; dns.lookup(arguments[1], function (err, ip, addressType) { @@ -991,7 +993,7 @@ Server.prototype.listen = function () { var self = this; if (self.fd) throw new Error('Server already opened'); - if (typeof(arguments[0]) == 'string') { + if (!isPort(arguments[0])) { // the first argument specifies a path self.fd = socket('unix'); self.type = 'unix'; -- 2.7.4