fix name regex

This commit is contained in:
Samuel Lorch 2024-07-28 21:22:08 +02:00
parent fca86ca590
commit 28e13f0192
2 changed files with 5 additions and 2 deletions

View file

@ -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)
}

View file

@ -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(())
}