From 787aa001b6078eb67c06baf94eb3858b3dc0cc57 Mon Sep 17 00:00:00 2001 From: Rimas Date: Thu, 12 Jan 2017 02:25:10 +0200 Subject: [PATCH] Fix not compressing trailing zeros in IPv6 Fixes a bug in the function findLongestZeroSequence, which ignored trailing zeros sequences. --- src/url-state-machine.js | 6 ++++++ test/to-upstream.json | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/url-state-machine.js b/src/url-state-machine.js index 10ad78d..4534bd6 100644 --- a/src/url-state-machine.js +++ b/src/url-state-machine.js @@ -417,6 +417,12 @@ function findLongestZeroSequence(arr) { } } + // if trailing zeros + if (currLen > maxLen) { + maxIdx = currStart; + maxLen = currLen; + } + return { idx: maxIdx, len: maxLen diff --git a/test/to-upstream.json b/test/to-upstream.json index 0d4f101..bce5fc4 100644 --- a/test/to-upstream.json +++ b/test/to-upstream.json @@ -1,2 +1,18 @@ [ + "# IPv6 trailing zeros compress test", + { + "input": "http://[1:0::]", + "base": "http://example.net/", + "href": "http://[1::]/", + "origin": "http://[1::]", + "protocol": "http:", + "username": "", + "password": "", + "host": "[1::]", + "hostname": "[1::]", + "port": "", + "pathname": "/", + "search": "", + "hash": "" + } ]