blob: bd1a6face1a8ec896f2a4739bc3b3d0883f7c301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Without FILTER_NULL_ON_FAILURE, php_filter_boolean trims surrounding
// whitespace, lowercases, and yields true only for "1"/"true"/"on"/"yes";
// every other input (including the "0"/"false"/"off"/"no"/"" set) yields
// false.
pub fn filter_var_boolean(value: &str) -> bool {
let trimmed = value.trim_matches([' ', '\t', '\n', '\r', '\0', '\x0B']);
matches!(
trimmed.to_ascii_lowercase().as_str(),
"1" | "true" | "on" | "yes"
)
}
// TODO(phase-c): PHP's FILTER_VALIDATE_URL parses with php_url_parse_ex and
// additionally validates the host as a domain/IPv6 literal. reqwest::Url
// (WHATWG/RFC 3986) is stricter on some inputs and more lenient on others,
// so this is not a byte-for-byte compatible validator.
pub fn filter_var_url(value: &str) -> bool {
reqwest::Url::parse(value).is_ok()
}
pub fn filter_var_email(_value: &str) -> bool {
todo!()
}
pub fn filter_var_ip(_value: &str) -> bool {
todo!()
}
pub fn filter_var_int_with_range(_value: &str, _min: i64, _max: i64) -> bool {
todo!()
}
|