File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
registry-scanner/pkg/image Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,9 @@ func (img *ContainerImage) String() string {
8080func (img * ContainerImage ) GetFullNameWithoutTag () string {
8181 str := ""
8282 if img .RegistryURL != "" {
83- str += img .RegistryURL + "/"
83+ if ! strings .HasPrefix (img .ImageName , img .RegistryURL + "/" ) {
84+ str += img .RegistryURL + "/"
85+ }
8486 }
8587 str += img .ImageName
8688 return str
@@ -91,7 +93,9 @@ func (img *ContainerImage) GetFullNameWithoutTag() string {
9193func (img * ContainerImage ) GetFullNameWithTag () string {
9294 str := ""
9395 if img .RegistryURL != "" {
94- str += img .RegistryURL + "/"
96+ if ! strings .HasPrefix (img .ImageName , img .RegistryURL + "/" ) {
97+ str += img .RegistryURL + "/"
98+ }
9599 }
96100 str += img .ImageName
97101 if img .ImageTag != nil {
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ func Test_ParseImageTags(t *testing.T) {
6363 assert .Equal (t , "0.1" , image .ImageTag .TagName )
6464 assert .Equal (t , "docker.io/jannfis/test-image:0.1" , image .GetFullNameWithTag ())
6565 assert .Equal (t , "docker.io/jannfis/test-image" , image .GetFullNameWithoutTag ())
66+
67+ // if the image name starts with registryURL, GetFullNameWithoutTag and GetFullNameWithTag
68+ // should return the correct full image name without repeating registryURL.
69+ // Wrong full image name: docker.io/docker.io/jannfis/test-image
70+ image .ImageName = "docker.io/jannfis/test-image"
71+ assert .Equal (t , "docker.io/jannfis/test-image:0.1" , image .GetFullNameWithTag ())
72+ assert .Equal (t , "docker.io/jannfis/test-image" , image .GetFullNameWithoutTag ())
6673 })
6774
6875 t .Run ("Parse valid image name with digest tag" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments