From e5449204c4036c7b4f66f66dd810e3a77b1b603a Mon Sep 17 00:00:00 2001 From: mkusaka Date: Mon, 18 Nov 2024 15:03:17 +0900 Subject: [PATCH] fix: handle Docker image tags with SHA256 hash Split Docker image tags at '@' to properly validate version numbers when SHA256 hash is present. --- pkg/parser/dockerImageParser.go | 5 +++++ pkg/parser/dockerImageParser_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pkg/parser/dockerImageParser.go b/pkg/parser/dockerImageParser.go index fced439a..bf5ab414 100644 --- a/pkg/parser/dockerImageParser.go +++ b/pkg/parser/dockerImageParser.go @@ -2,6 +2,7 @@ package parser import ( "regexp" + "strings" "github.com/CircleCI-Public/circleci-yaml-language-server/pkg/ast" ) @@ -36,6 +37,10 @@ func ParseDockerImageValue(value string) ast.DockerImageInfo { if tag != "" { // The regex includes the leading ":", just snip it tag = tag[1:] + // Split at "@" and take only the version part before it + if strings.Contains(tag, "@") { + tag = strings.Split(tag, "@")[0] + } } return ast.DockerImageInfo{ diff --git a/pkg/parser/dockerImageParser_test.go b/pkg/parser/dockerImageParser_test.go index 49afd0bc..8e3cfd4c 100644 --- a/pkg/parser/dockerImageParser_test.go +++ b/pkg/parser/dockerImageParser_test.go @@ -120,6 +120,19 @@ func Test_parseDockerImageValue(t *testing.T) { FullPath: "cimg/go:<>", }, }, + + { + name: "", + args: args{ + value: "cimg/node:22.11.0@sha256:76aae59c6259672ab68819b8960de5ef571394681089eab2b576f85f080c73ba", + }, + want: ast.DockerImageInfo{ + Namespace: "cimg", + Tag: "22.11.0", + Name: "node", + FullPath: "cimg/node:22.11.0@sha256:76aae59c6259672ab68819b8960de5ef571394681089eab2b576f85f080c73ba", + }, + }, } for _, tt := range tests {