From 8ac673d36efa8a2b9882e8d23c620c8dbf440456 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 19 Dec 2016 03:17:26 -0800 Subject: [PATCH] ip: less strict parsing. --- lib/utils/ip.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/utils/ip.js b/lib/utils/ip.js index a4007c44..d53a879f 100644 --- a/lib/utils/ip.js +++ b/lib/utils/ip.js @@ -224,36 +224,24 @@ IP.parseV6 = function parseV6(str, buf, offset) { var parts = str.split(':'); var missing = 8 - parts.length; var start = offset; - var len = parts.length; - var i = 0; - var word; + var colon = false; + var i, word; assert(missing >= 0, 'IPv6 address is too long.'); assert(parts.length >= 2, 'Not an IPv6 address.'); - if (parts[0].length === 0) { - assert(parts[1].length === 0, - 'Empty leading colon in IPv6 address.'); - missing += 1; - i++; - } else if (parts[len - 1].length === 0) { - assert(parts[len - 2].length === 0, - 'Empty trailing colon in IPv6 address.'); - missing += 1; - len--; - } - - for (; i < len; i++) { + for (i = 0; i < parts.length; i++) { word = parts[i]; if (word.length === 0) { - assert(missing > 0, 'Overuse of double colon in IPv6 address.'); + assert(!colon, 'Overuse of double colon in IPv6 address.'); + colon = true; missing += 1; // Eat extra colons. // e.g. :::0 - while (i + 1 < len) { + while (i + 1 < parts.length) { word = parts[i + 1]; if (word.length !== 0) break;