mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-06 11:34:25 +00:00
proxmox/tools/common_regex: improve IPRE_BRACKET
by disallowing [] around ipv4 adresses (which is not very common) we did not use this anywhere, so there should not be any compatibility problem Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
d79e1cfefe
commit
ef6ccff5d1
@ -41,14 +41,14 @@ macro_rules! IPV6RE { () => (concat!(r"(?:",
|
|||||||
macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
|
macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
|
||||||
|
|
||||||
/// Regular expression string to match IP addresses where IPv6 addresses require brackets around
|
/// Regular expression string to match IP addresses where IPv6 addresses require brackets around
|
||||||
/// them, while for IPv4 they are optional.
|
/// them, while for IPv4 they are forbidden.
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! IPRE_BRACKET { () => (
|
macro_rules! IPRE_BRACKET { () => (
|
||||||
concat!(r"(?:",
|
concat!(r"(?:",
|
||||||
IPV4RE!(),
|
IPV4RE!(),
|
||||||
r"|\[(?:",
|
r"|\[(?:",
|
||||||
IPV4RE!(), "|", IPV6RE!(),
|
IPV6RE!(),
|
||||||
r")\]",
|
r")\]",
|
||||||
r")"))
|
r")"))
|
||||||
}
|
}
|
||||||
@ -71,7 +71,6 @@ fn test_regexes() {
|
|||||||
assert!(IP_REGEX.is_match("2014:b3a:0102:adf1:1234:4321:4afA:BCDF"));
|
assert!(IP_REGEX.is_match("2014:b3a:0102:adf1:1234:4321:4afA:BCDF"));
|
||||||
|
|
||||||
assert!(IP_BRACKET_REGEX.is_match("127.0.0.1"));
|
assert!(IP_BRACKET_REGEX.is_match("127.0.0.1"));
|
||||||
assert!(IP_BRACKET_REGEX.is_match("[127.0.0.1]"));
|
|
||||||
assert!(IP_BRACKET_REGEX.is_match("[::1]"));
|
assert!(IP_BRACKET_REGEX.is_match("[::1]"));
|
||||||
assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::27]"));
|
assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::27]"));
|
||||||
assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::192.168.0.1]"));
|
assert!(IP_BRACKET_REGEX.is_match("[2014:b3a::192.168.0.1]"));
|
||||||
|
Loading…
Reference in New Issue
Block a user