fix(images): handle digest-like image references in tag splitting
- commit
- 3559512fd1a56b4f57abc5f917d43219ce60af6d
- author
- brice · · 2026-02-08 09:36 UTC
- committer
- brice · · 2026-02-08 09:40 UTC
- parent
- 351d7d0
- signature
- unsigned
2 files · +5 -0
M internal/usecase/images/service.go +3 -0
| @@ -351,6 +351,9 @@ func splitRepoTag(repoTag string) (string, string) { | |||
| 351 | 351 | if repoTag == "" { | |
| 352 | 352 | return "", "" | |
| 353 | 353 | } | |
| 354 | + | if strings.Contains(repoTag, "@") { | |
| 355 | + | return repoTag, "" | |
| 356 | + | } | |
| 354 | 357 | ||
| 355 | 358 | idx := strings.LastIndex(repoTag, ":") | |
| 356 | 359 | slashIdx := strings.LastIndex(repoTag, "/") | |
| @@ -351,6 +351,9 @@ func splitRepoTag(repoTag string) (string, string) { | |||||
| 351 | if repoTag == "" { | 351 | if repoTag == "" { | ||
| 352 | return "", "" | 352 | return "", "" | ||
| 353 | } | 353 | } | ||
| 354 | + | if strings.Contains(repoTag, "@") { | |||
| 355 | + | return repoTag, "" | |||
| 356 | + | } | |||
| 354 | 357 | ||||
| 355 | idx := strings.LastIndex(repoTag, ":") | 358 | idx := strings.LastIndex(repoTag, ":") | ||
| 356 | slashIdx := strings.LastIndex(repoTag, "/") | 359 | slashIdx := strings.LastIndex(repoTag, "/") | ||
M internal/usecase/images/service_test.go +2 -0
| @@ -622,8 +622,10 @@ func TestSplitRepoTag(t *testing.T) { | |||
| 622 | 622 | wantTag string | |
| 623 | 623 | }{ | |
| 624 | 624 | {name: "repository and tag", input: "alpine:latest", wantRepo: "alpine", wantTag: "latest"}, | |
| 625 | + | {name: "sha-like tag stays a tag", input: "image:sha256vdfhnijkvfedhbni", wantRepo: "image", wantTag: "sha256vdfhnijkvfedhbni"}, | |
| 625 | 626 | {name: "registry port and tag", input: "localhost:5000/repo:v1", wantRepo: "localhost:5000/repo", wantTag: "v1"}, | |
| 626 | 627 | {name: "registry port without tag", input: "localhost:5000/repo", wantRepo: "localhost:5000/repo", wantTag: ""}, | |
| 628 | + | {name: "digest reference not split as tag", input: "image@sha256:abcdef012345", wantRepo: "image@sha256:abcdef012345", wantTag: ""}, | |
| 627 | 629 | {name: "missing tag", input: "alpine", wantRepo: "alpine", wantTag: ""}, | |
| 628 | 630 | {name: "trailing colon", input: "alpine:", wantRepo: "alpine:", wantTag: ""}, | |
| 629 | 631 | } | |
| @@ -622,8 +622,10 @@ func TestSplitRepoTag(t *testing.T) { | |||||
| 622 | wantTag string | 622 | wantTag string | ||
| 623 | }{ | 623 | }{ | ||
| 624 | {name: "repository and tag", input: "alpine:latest", wantRepo: "alpine", wantTag: "latest"}, | 624 | {name: "repository and tag", input: "alpine:latest", wantRepo: "alpine", wantTag: "latest"}, | ||
| 625 | + | {name: "sha-like tag stays a tag", input: "image:sha256vdfhnijkvfedhbni", wantRepo: "image", wantTag: "sha256vdfhnijkvfedhbni"}, | |||
| 625 | {name: "registry port and tag", input: "localhost:5000/repo:v1", wantRepo: "localhost:5000/repo", wantTag: "v1"}, | 626 | {name: "registry port and tag", input: "localhost:5000/repo:v1", wantRepo: "localhost:5000/repo", wantTag: "v1"}, | ||
| 626 | {name: "registry port without tag", input: "localhost:5000/repo", wantRepo: "localhost:5000/repo", wantTag: ""}, | 627 | {name: "registry port without tag", input: "localhost:5000/repo", wantRepo: "localhost:5000/repo", wantTag: ""}, | ||
| 628 | + | {name: "digest reference not split as tag", input: "image@sha256:abcdef012345", wantRepo: "image@sha256:abcdef012345", wantTag: ""}, | |||
| 627 | {name: "missing tag", input: "alpine", wantRepo: "alpine", wantTag: ""}, | 629 | {name: "missing tag", input: "alpine", wantRepo: "alpine", wantTag: ""}, | ||
| 628 | {name: "trailing colon", input: "alpine:", wantRepo: "alpine:", wantTag: ""}, | 630 | {name: "trailing colon", input: "alpine:", wantRepo: "alpine:", wantTag: ""}, | ||
| 629 | } | 631 | } | ||