docker: Fix a bug where images with port number and no tags weren't parsed correctly

This commit is contained in:
Vincent Ducamps
2025-01-03 11:38:43 +01:00
committed by GitHub
parent f01c8aa66c
commit 6469b59a0a
3 changed files with 8 additions and 0 deletions

3
.changelog/24547.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
docker: Fix a bug where images with port number and no tags weren't parsed correctly
```

View File

@@ -2860,6 +2860,8 @@ func TestParseDockerImage(t *testing.T) {
Repo string
Tag string
}{
{"host:5000/library/hello-world", "host:5000/library/hello-world", "latest"},
{"host:5000/library/hello-world:1.0", "host:5000/library/hello-world", "1.0"},
{"library/hello-world:1.0", "library/hello-world", "1.0"},
{"library/hello-world", "library/hello-world", "latest"},
{"library/hello-world:latest", "library/hello-world", "latest"},

View File

@@ -31,6 +31,9 @@ func parseDockerImage(image string) (repo, tag string) {
} else if t := repoTag[idx+1:]; !strings.Contains(t, "/") {
repo = repoTag[:idx]
tag = t
} else if t := repoTag[idx+1:]; strings.Contains(t, "/") {
repo = image
tag = "latest"
}
if tag != "" {