Skip to content

Commit

Permalink
Bugfix: Support IPv6 leading zeros (#305)
Browse files Browse the repository at this point in the history
According to specification leading zeroes are optional but supported.

Adjusted validator implementation. Fixed the existing test which incorrectly documented a valid address as invalid.

See also:
- https://docs.oracle.com/cd/E18752_01/html/816-4554/ipv6-overview-10.html
- https://www.ibm.com/docs/en/i/7.2?topic=concepts-ipv6-address-types
- https://www.ietf.org/rfc/rfc2373.txt
  • Loading branch information
baldram authored Aug 16, 2022
1 parent 63de037 commit a398cd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait Regexs {
val oneDigitHex = Regex.hexDigit.exactly(1)
val twoDigitHex = Regex.hexDigitNonZero.exactly(1) ~ Regex.hexDigit.exactly(1)
val threeDigitHex = Regex.hexDigitNonZero.exactly(1) ~ Regex.hexDigit.exactly(2)
val fourDigitHex = Regex.hexDigitNonZero.exactly(1) ~ Regex.hexDigit.exactly(3)
val fourDigitHex = Regex.hexDigit.exactly(1) ~ Regex.hexDigit.exactly(3)

val hexGroup: Regex = fourDigitHex | threeDigitHex | twoDigitHex | oneDigitHex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,18 @@ object ValidationSpec extends DefaultRunnableSpec {
Seq(
"2001:470:9b36:1::2",
"2001:cdba:0:0:0:0:3257:9652",
"2001:cdba::3257:9652"
"2001:cdba::3257:9652",
"0000:0000:0000:0000:0000:0000:0000:0001",
"0:0:0:0:0:0:0:1",
"0000:0000:0000:0000:0000:0000:0000:0000",
"2001:0000:0000:0000:0000:0001:0000:0000",
"0:0:0:0:0:0:0:0",
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
"2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b",
"12AB:0000:0000:CD30:0000:0000:0000:0000",
"12AB::CD30:0:0:0:0",
"12AB:0:0:CD30::",
"2001:cdba:0000:0000:0000:0000:3257:9652"
)
}

Expand All @@ -192,7 +203,6 @@ object ValidationSpec extends DefaultRunnableSpec {
Seq(
"2001:db8:122:344::192.0.2.33",
"1200::AB00:1234::2552:7777:1313",
"2001:cdba:0000:0000:0000:0000:3257:9652",
"1200:0000:AB00:1234:O000:2552:7777:1313"
)
}
Expand Down

0 comments on commit a398cd9

Please sign in to comment.