43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
pub(crate) fn valid_percent_encoding(value: &str) -> bool {
|
|
let bytes = value.as_bytes();
|
|
let mut index = 0;
|
|
while index < bytes.len() {
|
|
if bytes[index] == b'%' {
|
|
if index + 2 >= bytes.len()
|
|
|| !bytes[index + 1].is_ascii_hexdigit()
|
|
|| !bytes[index + 2].is_ascii_hexdigit()
|
|
{
|
|
return false;
|
|
}
|
|
index += 3;
|
|
} else {
|
|
index += 1;
|
|
}
|
|
}
|
|
true
|
|
}
|
|
|
|
pub(crate) fn valid_database_host(value: &str) -> bool {
|
|
!value.is_empty()
|
|
&& value.len() <= 253
|
|
&& !value.chars().any(char::is_whitespace)
|
|
&& (value.parse::<std::net::IpAddr>().is_ok()
|
|
|| value.split('.').all(|label| {
|
|
!label.is_empty()
|
|
&& label.len() <= 63
|
|
&& label
|
|
.bytes()
|
|
.all(|byte| byte.is_ascii_alphanumeric() || byte == b'-')
|
|
&& !label.starts_with('-')
|
|
&& !label.ends_with('-')
|
|
}))
|
|
}
|
|
|
|
pub(crate) fn valid_database_identifier(value: &str) -> bool {
|
|
!value.is_empty()
|
|
&& value.len() <= 128
|
|
&& value
|
|
.bytes()
|
|
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-' | b'.'))
|
|
}
|