Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

net: make isIP() return 0 on empty input

  • Loading branch information...
rsolomo authored and bnoordhuis committed May 14, 2012
1 parent 38542f7 commit d40415912f0807201a45d82a86a7f6e316bad5d7
Showing with 5 additions and 4 deletions.
  1. +1 −1 lib/net.js
  2. +4 −3 test/simple/test-net-isip.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++) {
@@ -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);

2 comments on commit d404159

@felixge

This comment has been minimized.

Copy link

replied May 14, 2012

Any particular reason why we return 0 here instead of false? (other than BC)

@bnoordhuis

This comment has been minimized.

Copy link
Member

replied May 14, 2012

None except that it's what the docs say net.isIP("") returns.

Please sign in to comment.
You can’t perform that action at this time.