See distribution/distribution#3665
I'm working on simplifying my OCI registry at Trow-Registry/trow#483 by relying more on existing crates, but I have a test failure when resolving a reference that points to an ipv6 ([::1]:34321/alpine/manifests/latest)
The working regex I had in trow for image references was:
/// The regex validates an image reference.
/// It returns `name`, `tag` and `digest`.
///
/// Built from:
/// https://github.com/distribution/reference/blob/727f80d42224f6696b8e1ad16b06aadf2c6b833b/regexp.go
const fn get_image_ref_regex() -> &'static str {
const SEPARATOR: &str = "(?:[._]|__|[-]+)";
const ALPHANUMERIC: &str = "[a-z0-9]+";
const DOMAIN_COMPONENT: &str = "(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])";
const NAME_COMPONENT: &str = formatcp!("{ALPHANUMERIC}(?:{SEPARATOR}{ALPHANUMERIC})*");
const DOMAIN_NAME: &str = formatcp!("{DOMAIN_COMPONENT}(?:[.]{DOMAIN_COMPONENT})*");
const IPV6_ADDR: &str = r"\[(?:[a-fA-F0-9:]+)\]";
const DOMAIN: &str = formatcp!("(?:{DOMAIN_NAME}|{IPV6_ADDR})(?::[0-9]+)?");
const DIGEST: &str = "[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}";
const TAG: &str = r"[\w][\w.-]{0,127}";
const NAME: &str = formatcp!("(?:{DOMAIN}/)?{NAME_COMPONENT}(/{NAME_COMPONENT})*");
formatcp!("^(?P<name>{NAME})(?::(?P<tag>{TAG}))?(?:@(?P<digest>{DIGEST}))?$")
}
Compared to oci-spec-rs's regex:
|
const REFERENCE_REGEXP: &str = r"^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\w][\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}))?$"; |
See distribution/distribution#3665
I'm working on simplifying my OCI registry at Trow-Registry/trow#483 by relying more on existing crates, but I have a test failure when resolving a reference that points to an ipv6 (
[::1]:34321/alpine/manifests/latest)The working regex I had in trow for image references was:
Compared to oci-spec-rs's regex:
oci-spec-rs/src/distribution/reference.rs
Line 18 in f496b8a