Repository navigation
fix(properties): keep NewReferenceList's digest for a tag and digest - #1450
Conversation
NewReferenceList dropped a digest that followed the tags. A single "repo:v1@sha256:..." came back as plain "repo:v1", disagreeing with NewReference on the same input, and "repo:v1,v2@sha256:..." returned two plain tags although the function documents that all references in a list are of one type. Return a single tag with a digest as the one reference NewReference parses, and reject a list of tags combined with a digest with ErrInvalidReference. Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
NewReference skips the tag check when a digest is present, so "repo: v1 @sha256:..." kept the spaces in its tag and "repo:bad tag@..." was accepted. Trim and validate the tag as the comma-separated path does. Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
TerryHowe
left a comment
There was a problem hiding this comment.
Re-reviewed at 6597011. Fetched the branch, built it, ran go vet and go test ./registry/... â all pass, gofmt clean.
The trimming/validation asymmetry is fixed and covered by tests. Verified behavior:
"localhost:5000/repo: v1 @sha256:âĶ" -> [Tag "v1", Digest sha256:âĶ] (was Tag " v1 ")
"localhost:5000/repo:bad tag@sha256:âĶ" -> invalid reference: invalid tag "bad tag" (was accepted)
"localhost:5000/repo:v1,v2@sha256:âĶ" -> invalid reference: a list of tags cannot be combined with a digest
"oci://LOCALHOST:5000/nested/repo:v1@âĶ" -> localhost:5000/nested/repo:v1@âĶ (scheme strip, lower-casing, nested path intact)
"localhost:5000/repo:@d1,d2" -> two digest refs (unchanged, as the PR body states)
LGTM. Nothing below blocks the merge.
Follow-up worth filing separately
NewReferenceList is now stricter than NewReference for the same input, because NewReference skips ValidateTag whenever Digest != "" (reference.go:126-134):
NewReference("localhost:5000/repo:bad tag@sha256:âĶ") // Tag "bad tag", no error
NewReferenceList("localhost:5000/repo:bad tag@sha256:âĶ") // invalid reference: invalid tag "bad tag"The doc comment no longer claims parity with NewReference, so this PR is self-consistent â but NewReference accepting a regex-invalid tag in Form B looks like a real bug, and fixing it there would make the explicit ValidateTag call here redundant. Suggest an issue rather than expanding this PR.
Optional polish
tag@digest1,digest2is rejected withinvalid digest "sha256:âĶ,sha256:âĶ": invalid checksum digest length, while its mirrortag1,tag2@digestgets a clear mixed-type message. Astrings.Contains(digestRef, ",")check would make the two symmetric.- The doc comment covers trimming and validation now, but not that
tag@digest1,digest2is rejected, nor thatrepo:@d1,d2parses as a digest list with the empty tag dropped. The latter is the least obvious behavior here and is documented only in the PR description. - No test pins
repo:@d1,d2, the case the PR body calls out as an intentional non-change. - In the table loop,
len(refs) != tt.wantCountreports witht.Errorfbut doesn'treturn, and the loop then indexestt.wantTags[i]/tt.wantDigests[i]. Areturnthere would make a future regression fail cleanly instead of panicking.
Codecov Reportâ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1450 +/- ##
==========================================
+ Coverage 91.00% 91.01% +0.01%
==========================================
Files 97 97
Lines 7358 7368 +10
==========================================
+ Hits 6696 6706 +10
Misses 651 651
Partials 11 11 â View full report in Codecov by Harness. ð New features to boost your workflow:
|
NewReferenceListdropped a digest that followed the tags:NewReferenceList("localhost:5000/repo:v1@sha256:âĶ")returnedrepo:v1with no digest, whileNewReferenceon the same string returns the tag and the digest.NewReferenceList("localhost:5000/repo:v1,v2@sha256:âĶ")returned two plain tags, although the doc says every reference in a list is of one type.A single tag with a digest now returns one reference with both, its tag trimmed and validated like the tags in a list, and a list of tags combined with a digest returns
ErrInvalidReference.Not changed:
repo:@d1,d2(an empty tag followed by a digest list) is still read as a digest list.