Skip to main content

normalize_image_ref

Function normalize_image_ref 

Source
pub fn normalize_image_ref(image: &str) -> String
Expand description

Canonicalize an OCI image reference.

All equivalent spellings of the same image produce an identical string, which is safe to use as a cache key or protocol field.

§Normalization rules (applied in order)

  1. index.docker.io is rewritten to docker.io (legacy alias).
  2. A missing registry defaults to docker.io.
  3. Single-component names on docker.io receive the library/ prefix (e.g. alpinedocker.io/library/alpine).
  4. A missing tag defaults to :latest. When a digest (@sha256:…) is present it takes precedence and any tag is dropped.

§Examples

use smolvm_protocol::normalize_image_ref;

assert_eq!(normalize_image_ref("alpine"),
           "docker.io/library/alpine:latest");
assert_eq!(normalize_image_ref("alpine:3.20"),
           "docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("docker.io/alpine:3.20"),
           "docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("docker.io/library/alpine:3.20"),
           "docker.io/library/alpine:3.20");
assert_eq!(normalize_image_ref("ghcr.io/owner/repo:v1"),
           "ghcr.io/owner/repo:v1");