aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2020-10-12 20:02:58 -0700
committerRichard Walters <rwalters@digitalstirling.com>2020-10-12 20:02:58 -0700
commit4accf8c296ef7a1f6bd10a90b7a06b3b499ccda6 (patch)
treead2af039038bea44e27d9470c6691c5f34474576
parentc1f5c485b47222ad451c484966d702a9539dede4 (diff)
Fix bugs in validating numbers of IPv6 address groups
-rw-r--r--src/lib.rs7
-rw-r--r--test/src/UriTests.cpp3
2 files changed, 8 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c707b8b..54455b0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -473,8 +473,8 @@ fn validate_ipv6_address<T>(address: T) -> Result<(), Error>
match (double_colon_encountered, num_groups) {
(true, n) if n <= 7 => Ok(()),
(false, 8) => Ok(()),
- (_, n) if n > 8 => Err(Error::TooManyAddressParts),
- (_, _) => Err(Error::TooFewAddressParts),
+ (false, n) if n < 8 => Err(Error::TooFewAddressParts),
+ (_, _) => Err(Error::TooManyAddressParts),
}
}
@@ -2049,6 +2049,8 @@ mod tests {
("http://[::1]/", "::1").into(),
("http://[::ffff:1.2.3.4]/", "::ffff:1.2.3.4").into(),
("http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/", "2001:db8:85a3:8d3:1319:8a2e:370:7348").into(),
+ ("http://[2001:db8:85a3:8d3:1319:8a2e:370::]/", "2001:db8:85a3:8d3:1319:8a2e:370::").into(),
+ ("http://[2001:db8:85a3:8d3:1319:8a2e::1]/", "2001:db8:85a3:8d3:1319:8a2e::1").into(),
("http://[fFfF::1]", "fFfF::1").into(),
("http://[1234::1]", "1234::1").into(),
("http://[fFfF:1:2:3:4:5:6:a]", "fFfF:1:2:3:4:5:6:a").into(),
@@ -2087,6 +2089,7 @@ mod tests {
("http://[::ffff:1.2.3.4/", Error::TruncatedHost).into(),
("http://[2001:db8:85a3:8d3:1319:8a2e:370:7348:0000]/", Error::TooManyAddressParts).into(),
("http://[2001:db8:85a3:8d3:1319:8a2e:370:7348::1]/", Error::TooManyAddressParts).into(),
+ ("http://[2001:db8:85a3:8d3:1319:8a2e:370::1]/", Error::TooManyAddressParts).into(),
("http://[2001:db8:85a3::8a2e:0:]/", Error::TruncatedHost).into(),
("http://[2001:db8:85a3::8a2e::]/", Error::TooManyDoubleColons).into(),
("http://[]/", Error::TooFewAddressParts).into(),
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 6a16740..4848724 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -730,6 +730,8 @@ TEST(UriTests, IPv6Address) {
{"http://[::1]/", "::1", true},
{"http://[::ffff:1.2.3.4]/", "::ffff:1.2.3.4", true},
{"http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/", "2001:db8:85a3:8d3:1319:8a2e:370:7348", true},
+ {"http://[2001:db8:85a3:8d3:1319:8a2e:370::]/", "2001:db8:85a3:8d3:1319:8a2e:370::", true},
+ {"http://[2001:db8:85a3:8d3:1319:8a2e::1]/", "2001:db8:85a3:8d3:1319:8a2e::1", true},
{"http://[fFfF::1]", "fFfF::1", true},
{"http://[1234::1]", "1234::1", true},
{"http://[fFfF:1:2:3:4:5:6:a]", "fFfF:1:2:3:4:5:6:a", true},
@@ -753,6 +755,7 @@ TEST(UriTests, IPv6Address) {
{"http://::ffff:1.a.3.4]/", "", false},
{"http://[2001:db8:85a3:8d3:1319:8a2e:370:7348:0000]/", "", false},
{"http://[2001:db8:85a3:8d3:1319:8a2e:370:7348::1]/", "", false},
+ {"http://[2001:db8:85a3:8d3:1319:8a2e:370::1]/", "", false},
{"http://[2001:db8:85a3::8a2e:0:]/", "", false},
{"http://[2001:db8:85a3::8a2e::]/", "", false},
{"http://[]/", "", false},