Skip to content

Commit

Permalink
Fix name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Apr 25, 2024
1 parent 4b71b42 commit 335378e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ocipkg/src/distribution/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl fmt::Display for Name {
}

lazy_static::lazy_static! {
static ref NAME_RE: Regex = Regex::new(r"^[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*$").unwrap();
static ref NAME_RE: Regex = Regex::new(r"^[A-Za-z0-9]+([._-][A-Za-z0-9]+)*(/[A-Za-z0-9]+([._-][A-Za-z0-9]+)*)*$").unwrap();
}

impl Name {
Expand Down
18 changes: 18 additions & 0 deletions ocipkg/src/image_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,21 @@ impl ImageName {
Ok(Url::parse(&url)?)
}
}

#[cfg(test)]
mod test {
use crate::ImageName;

#[test]
fn ttlsh_style() {
let image_name =
ImageName::parse("ttl.sh/79219A62-4E86-41B3-854D-95D8F4636C9C:1h").unwrap();
assert_eq!(image_name.hostname, "ttl.sh".to_string(),);
assert_eq!(image_name.port, None);
assert_eq!(
image_name.name.as_str(),
"79219A62-4E86-41B3-854D-95D8F4636C9C"
);
assert_eq!(image_name.reference.as_str(), "1h")
}
}

0 comments on commit 335378e

Please sign in to comment.