Skip to content
Permalink
Browse files

lib/util: Fix parsing compact ipv6

  • Loading branch information...
lauriro committed Aug 10, 2019
1 parent faac2e8 commit 12f468c46490fb4c748fd547d35405b9a2100ea0
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/util.js
  2. +10 −0 test/lib/util.js
@@ -154,7 +154,7 @@ function ip2buf(str) {
arr[len] = (
arr[len] !== "" ?
("0000" + arr[len]).slice(-4) :
"00000000000000000000000000000000".slice(-4*(8-arr.length))
"00000000000000000000000000000000".slice(-4*(9 - arr.length))
)
}
return Buffer.from(arr.join(""), "hex")
@@ -70,6 +70,8 @@ require("..")
compare("127.0.0.1", "7f000001")
compare("ffff::255.255.255.255", "ffffffff", "255.255.255.255")
compare("2001:0000:1234:0000:0000:c1c0:abcd:0876", "20010000123400000000C1C0ABCD0876")
compare("2001:0000:1234::c1c0:abcd:0876", "20010000123400000000C1C0ABCD0876", "2001:0000:1234:0000:0000:c1c0:abcd:0876")
compare("2001::c1c0:abcd:0876", "20010000000000000000C1C0ABCD0876", "2001:0000:0000:0000:0000:c1c0:abcd:0876")

assert.end()
})
@@ -86,6 +88,7 @@ require("..")

.equal(util.ipInNet("192.168.99.255", "192.168.100.0/22"), false)
.equal(util.ipInNet("192.168.100.0", "192.168.100.0/22"), true)
.equal(util.ipInNet("192.168.100.0", "192.168.100"), true)
.equal(util.ipInNet("192.168.103.255", "192.168.100.0/22"), true)
.equal(util.ipInNet("192.168.104.0", "192.168.100.0/22"), false)

@@ -276,4 +279,11 @@ require("..")

assert.end()
})
.it("should have uuid4/rand/round", function(assert) {
assert
.equal(util.uuid4().length, 36)
.equal(util.rand(36).length, 36)
.equal(util.round(1.005, 2), 1.01)
.end()
})

0 comments on commit 12f468c

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