From cebdbc7ad057a4f4e0ca67ad63b88eb558f82e56 Mon Sep 17 00:00:00 2001 From: ppom Date: Sat, 2 Aug 2025 12:00:00 +0200 Subject: [PATCH] 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. --- src/concepts/pattern/ip/mod.rs | 3 ++- src/concepts/pattern/ip/utils.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/concepts/pattern/ip/mod.rs b/src/concepts/pattern/ip/mod.rs index 2fdfd80..3bf727c 100644 --- a/src/concepts/pattern/ip/mod.rs +++ b/src/concepts/pattern/ip/mod.rs @@ -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")); diff --git a/src/concepts/pattern/ip/utils.rs b/src/concepts/pattern/ip/utils.rs index a294c55..2e1ad66 100644 --- a/src/concepts/pattern/ip/utils.rs +++ b/src/concepts/pattern/ip/utils.rs @@ -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]