app_json_settings/core/
validation.rs1use crate::core::error::{ConfigError, Result};
2
3pub fn is_plain_file_name(value: &str) -> bool {
8 is_safe_path_component(value)
9}
10
11pub fn is_safe_path_component(value: &str) -> bool {
13 !value.is_empty()
14 && value != "."
15 && value != ".."
16 && !value.contains('/')
17 && !value.contains('\\')
18 && !value.contains(':')
19 && !value.chars().any(char::is_control)
20}
21
22pub fn validate_plain_file_name(value: &str) -> Result<&str> {
23 if is_plain_file_name(value) {
24 Ok(value)
25 } else {
26 Err(ConfigError::InvalidPathComponent(value.to_string()))
27 }
28}
29
30pub fn validate_path_component(value: &str) -> Result<&str> {
31 if is_safe_path_component(value) {
32 Ok(value)
33 } else {
34 Err(ConfigError::InvalidPathComponent(value.to_string()))
35 }
36}