isIP test
This commit is contained in:
Родитель
e81a89b116
Коммит
1018e7d23f
|
@ -563,6 +563,8 @@ Server.prototype.close = function() {
|
|||
|
||||
// TODO: isIP should be moved to the DNS code. Putting it here now because
|
||||
// this is what the legacy system did.
|
||||
// NOTE: This does not accept IPv6 with an IPv4 dotted address at the end,
|
||||
// and it does not detect more than one double : in a string.
|
||||
exports.isIP = function(input) {
|
||||
if (!input) {
|
||||
return 4;
|
||||
|
@ -575,7 +577,7 @@ exports.isIP = function(input) {
|
|||
}
|
||||
}
|
||||
return 4;
|
||||
} else if (/^(::)?([a-fA-F0-9]+(::?)?)*$/.test(input)) {
|
||||
} else if (/^::|^::1|^([a-fA-F0-9]{1,4}::?){1,7}([a-fA-F0-9]{1,4})$/.test(input)) {
|
||||
return 6;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
@ -32,6 +32,10 @@ assert.equal(net.isIP('1050:0:0:0:5:600:300c:326b'), 6);
|
|||
assert.equal(net.isIP('2001:252:0:1::2008:6'), 6);
|
||||
assert.equal(net.isIP('2001:dead:beef:1::2008:6'), 6);
|
||||
assert.equal(net.isIP('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 6);
|
||||
assert.equal(net.isIP('::1'), 6);
|
||||
assert.equal(net.isIP('::'), 6);
|
||||
assert.equal(net.isIP('0000:0000:0000:0000:0000:0000:00001:0000'), 0);
|
||||
assert.equal(net.isIP('0'), 0);
|
||||
|
||||
assert.equal(net.isIPv4('127.0.0.1'), true);
|
||||
assert.equal(net.isIPv4('example.com'), false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче