mirror of https://github.com/nodejs/node.git
net: make isIP() return 0 on empty input
parent
38542f76a9
commit
d40415912f
|
@ -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);
|
Loading…
Reference in New Issue