Compare commits

..

1 commit

Author SHA1 Message Date
Samuel Lorch
cfb3d0a3b0 Add name validation 2024-07-27 23:16:07 +02:00
2 changed files with 2 additions and 5 deletions

View file

@ -178,7 +178,6 @@ fn read_file_to_config(path: &str) -> Result<Config, ConfigError> {
if conf.config_version != 1 {
return Err(ConfigError::UnsupportedVersionError);
}
conf.validate()?;
Ok(conf)
}

View file

@ -3,16 +3,14 @@ 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(REGEX_NAME).unwrap());
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"/^[0-9A-Za-z_-]*$/g").unwrap());
if !RE.is_match(value) {
return Err(garde::Error::new("name must only contain a-zA-Z0-9._/-"));
return Err(garde::Error::new("name must only contain 0-9A-Za-z_-"));
}
Ok(())
}