mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-07 17:18:21 +00:00
fix name regex
This commit is contained in:
parent
fca86ca590
commit
28e13f0192
2 changed files with 5 additions and 2 deletions
|
@ -178,6 +178,7 @@ fn read_file_to_config(path: &str) -> Result<Config, ConfigError> {
|
|||
if conf.config_version != 1 {
|
||||
return Err(ConfigError::UnsupportedVersionError);
|
||||
}
|
||||
conf.validate()?;
|
||||
Ok(conf)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,16 @@ use {
|
|||
regex::Regex,
|
||||
};
|
||||
|
||||
const REGEX_NAME: &str = r"^[a-zA-Z0-9._/-]*$";
|
||||
|
||||
pub fn validate_name(value: &str, _: &Config) -> garde::Result {
|
||||
if value.len() > 32 {
|
||||
return Err(garde::Error::new("name is longer than 32"));
|
||||
}
|
||||
|
||||
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"/^[0-9A-Za-z_-]*$/g").unwrap());
|
||||
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(REGEX_NAME).unwrap());
|
||||
if !RE.is_match(value) {
|
||||
return Err(garde::Error::new("name must only contain 0-9A-Za-z_-"));
|
||||
return Err(garde::Error::new("name must only contain a-zA-Z0-9._/-"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue