ipv4 regex: do no accept numbers 0[0-9]

The Rust std won't accept it anyway, as it interprets numbers starting
with 0 as octal numbers and forbid that.
This commit is contained in:
ppom 2025-08-02 12:00:00 +02:00
commit cebdbc7ad0
No known key found for this signature in database
2 changed files with 4 additions and 1 deletions

View file

@ -45,7 +45,7 @@ impl PatternType {
// then 1xx
"1[0-9][0-9]",
// then 0xx
"[0-9][0-9]",
"[1-9][0-9]",
// then 0x
"[0-9])",
]
@ -641,6 +641,7 @@ mod patternip_tests {
assert2!(!regex.is_match("1.2.3.4 "));
assert2!(!regex.is_match("1.2. 3.4"));
assert2!(!regex.is_match("257.2.3.4"));
assert2!(!regex.is_match("074.2.3.4"));
assert2!(!regex.is_match("1.2.3.4.5"));
assert2!(!regex.is_match("1.2..4"));
assert2!(!regex.is_match("1.2..3.4"));

View file

@ -79,6 +79,8 @@ mod utils_tests {
normalize("::ffff:1.2.3.4"),
Ok(IpAddr::V4(Ipv4Addr::new(1, 2, 3, 4)))
);
// octal numbers are forbidden
assert!(normalize("083.44.23.14").is_err());
}
#[test]