Fix invalid IPv6 notation

This commit is contained in:
Pierre HUBERT 2024-01-05 09:11:00 +01:00
parent 524ab50df7
commit 134e27feb6
2 changed files with 6 additions and 3 deletions

View File

@ -32,7 +32,7 @@ pub fn is_ipv4_mask_valid(mask: u8) -> bool {
}
pub fn is_ipv6_mask_valid(mask: u8) -> bool {
mask <= 64
mask <= 128
}
pub fn is_mask_valid(ipv: usize, mask: u8) -> bool {
@ -79,6 +79,7 @@ mod tests {
assert!(is_ipv6_address_valid("fe80::"));
assert!(is_ipv6_address_valid("fe80:dd::"));
assert!(is_ipv6_address_valid("00:00:00:00:00::"));
assert!(is_ipv6_address_valid("0:0:0:0:0:0:0:0"));
assert!(!is_ipv6_address_valid("tata"));
assert!(!is_ipv6_address_valid("2.56.58.156"));
@ -93,6 +94,8 @@ mod tests {
assert!(is_mask_valid(6, 34));
assert!(!is_mask_valid(4, 34));
assert!(!is_mask_valid(6, 69));
assert!(is_mask_valid(6, 69));
assert!(is_mask_valid(6, 128));
assert!(!is_mask_valid(6, 129));
}
}

View File

@ -128,6 +128,6 @@ function sanitizeMask(version: 4 | 6, mask?: string): number | undefined {
if (version === 4) {
return value < 0 || value > 32 ? 32 : value;
} else {
return value < 0 || value > 64 ? 64 : value;
return value < 0 || value > 128 ? 128 : value;
}
}