From b9c0f2c987688a8e7ee2c8f4e4fbf6b1a8fee024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 9 Jan 2019 21:38:49 +0100 Subject: [PATCH] Use reference.TagNameOnly instead of manually adding imageParts.tag in normalizeTag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Again, rely on the official API, instead of the suprising "suspiciousTagValueForSearch" value (set to :latest on untagged images, and :none on digested ones!) CHANGES BEHAVIOR, but the previous output of normalization of digested values was not even syntatically valid, so this can't really be worse. Still, maybe we should refuse to tag with digested references in the first place. Signed-off-by: Miloslav Trmač --- libpod/image/image.go | 7 ++----- libpod/image/image_test.go | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/libpod/image/image.go b/libpod/image/image.go index 2457a1c229..0b743e1441 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -471,12 +471,9 @@ func normalizeTag(tag string) (string, error) { return "", err } } - tag = ref.String() // If the input does not have a tag, we need to add one (latest) - if !decomposedTag.isTagged { - tag = fmt.Sprintf("%s:%s", tag, decomposedTag.tag) - } - return tag, nil + ref = reference.TagNameOnly(ref) + return ref.String(), nil } // TagImage adds a tag to the given image diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index a85cd5386d..96148c2cd5 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -264,7 +264,7 @@ func TestNormalizeTag(t *testing.T) { {"#", ""}, // Clearly invalid {"example.com/busybox", "example.com/busybox:latest"}, // Qualified name-only {"example.com/busybox:notlatest", "example.com/busybox:notlatest"}, // Qualified name:tag - {"example.com/busybox" + digestSuffix, "example.com/busybox" + digestSuffix + ":none"}, // Qualified name@digest; FIXME: The result is not even syntactically valid! + {"example.com/busybox" + digestSuffix, "example.com/busybox" + digestSuffix}, // Qualified name@digest; FIXME? Should we allow tagging with a digest at all? {"example.com/busybox:notlatest" + digestSuffix, "example.com/busybox:notlatest" + digestSuffix}, // Qualified name:tag@digest {"busybox:latest", "localhost/busybox:latest"}, // Unqualified name-only {"ns/busybox:latest", "localhost/ns/busybox:latest"}, // Unqualified with a dot-less namespace