diff --git a/lib/net.js b/lib/net.js index fa6258ba435..9705f557a73 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1030,7 +1030,7 @@ Server.prototype.listenFD = function(fd, type) { // and it does not detect more than one double : in a string. exports.isIP = function(input) { if (!input) { - return 4; + return 0; } else if (/^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$/.test(input)) { var parts = input.split('.'); for (var i = 0; i < parts.length; i++) { diff --git a/test/simple/test-net-isip.js b/test/simple/test-net-isip.js index 75da204c039..4f60f502135 100644 --- a/test/simple/test-net-isip.js +++ b/test/simple/test-net-isip.js @@ -36,12 +36,13 @@ assert.equal(net.isIP('::1'), 6); assert.equal(net.isIP('::'), 6); assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:12345:0000'), 0); assert.equal(net.isIP('0'), 0); +assert.equal(net.isIP(), 0); +assert.equal(net.isIP(""), 0); assert.equal(net.isIPv4('127.0.0.1'), true); assert.equal(net.isIPv4('example.com'), false); assert.equal(net.isIPv4('2001:252:0:1::2008:6'), false); assert.equal(net.isIPv6('127.0.0.1'), false); -assert.equal(net.isIPv4('example.com'), false); -assert.equal(net.isIPv6('2001:252:0:1::2008:6'), true); - +assert.equal(net.isIPv6('example.com'), false); +assert.equal(net.isIPv6('2001:252:0:1::2008:6'), true); \ No newline at end of file