aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim/src/filter.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 15:49:24 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 15:49:37 +0900
commitfcef25f6ef36287a4984ffdaab39df84f5aceeba (patch)
tree97ceb2098fbb5642e858929da9578bb41e277ada /crates/shirabe-php-shim/src/filter.rs
parentf0f5f084c883dc4f5b6e61603e82cd1c2092fd9d (diff)
downloadphp-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.tar.gz
php-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.tar.zst
php-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.zip
refactor(php-shim): split lib.rs
Diffstat (limited to 'crates/shirabe-php-shim/src/filter.rs')
-rw-r--r--crates/shirabe-php-shim/src/filter.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/filter.rs b/crates/shirabe-php-shim/src/filter.rs
new file mode 100644
index 0000000..a23752b
--- /dev/null
+++ b/crates/shirabe-php-shim/src/filter.rs
@@ -0,0 +1,39 @@
+use crate::PhpMixed;
+use indexmap::IndexMap;
+
+pub const FILTER_VALIDATE_EMAIL: i64 = 274;
+
+pub const FILTER_VALIDATE_BOOLEAN: i64 = 258;
+pub const FILTER_VALIDATE_URL: i64 = 273;
+pub const FILTER_VALIDATE_IP: i64 = 275;
+pub const FILTER_VALIDATE_INT: i64 = 257;
+
+pub fn filter_var(value: &str, filter: i64) -> bool {
+ match filter {
+ // 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.
+ FILTER_VALIDATE_BOOLEAN => {
+ 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.
+ FILTER_VALIDATE_URL => reqwest::Url::parse(value).is_ok(),
+ _ => todo!(),
+ }
+}
+
+pub fn filter_var_with_options(
+ _value: &str,
+ _filter: i64,
+ _options: &IndexMap<String, PhpMixed>,
+) -> PhpMixed {
+ todo!()
+}