c8d: Fix resolving truncated id to a descriptor

Regular expression beginning anchor was placed after `sha256:` digest
prefix.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-01-18 11:59:50 +01:00
parent d783e7df83
commit 596c8960b2
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A

View file

@ -180,7 +180,7 @@ func (i *ImageService) resolveDescriptor(ctx context.Context, refOrID string) (o
if truncatedID.MatchString(refOrID) {
filters := []string{
fmt.Sprintf("name==%q", ref), // Or it could just look like one.
"target.digest~=" + strconv.Quote(fmt.Sprintf(`sha256:^%s[0-9a-fA-F]{%d}$`, regexp.QuoteMeta(refOrID), 64-len(refOrID))),
"target.digest~=" + strconv.Quote(fmt.Sprintf(`^sha256:%s[0-9a-fA-F]{%d}$`, regexp.QuoteMeta(refOrID), 64-len(refOrID))),
}
imgs, err := is.List(ctx, filters...)
if err != nil {