ImageNameWithDigest produces invalid OCI reference when Build.Image is empty
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
Research direction
Start in pkg/functions/function.go:860-880 at Function.ImageNameWithDigest and review how an empty Build.Image reaches reference construction. Verify that an empty image with a non-empty digest produces an empty result, while the existing empty-digest behavior remains unchanged; run the relevant package tests and add a focused regression test if the package test layout supports it.
Written by the indexing model from the issue text.
Description
Description
ImageNameWithDigest in pkg/functions/function.go does not validate that f.Build.Image is non-empty before processing. When called with a non-empty newDigest but an empty image name, it produces the malformed OCI reference @sha256:... (missing the image name prefix).
Steps to Reproduce
This occurs when Push returns a digest but the function's Build.Image was never set (e.g., if the build process was interrupted or the function was loaded from a corrupt state).
f := fn.Function{Build: fn.BuildSpec{Image: ""}}
result := f.ImageNameWithDigest("sha256:abc123def...")
fmt.Println(result) // "@sha256:abc123def..." -- invalid
Expected Behavior
The function should return an empty string when Build.Image is empty, rather than producing a malformed reference.
Actual Behavior
Returns @sha256:abc123... which fails name.ParseReference downstream with a confusing "could not parse reference" error.
Relevant Code
// pkg/functions/function.go:860-880
func (f Function) ImageNameWithDigest(newDigest string) string {
if newDigest == "" {
return f.Build.Image
}
image := f.Build.Image // no empty check!
// ...
lastSlashIdx := strings.LastIndexAny(image, "/") // -1 for empty string
// produces "@sha256:..." with no image name prefix
}
Suggested Fix
Add an early return for empty image:
image := f.Build.Image
if image == "" {
return ""
}
- Dominant language
- Go
- Stars
- 365
- Forks
- 223
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 25
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from knative/func
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
setServiceOptions: %f format produces invalid autoscaling annotation values with trailing zeros Openlifecycle/stale
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
bug carvel-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
carvel-dev/kapp-controller#1861 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100