(selector string, image2 string)
| 77 | } |
| 78 | |
| 79 | func CompareImageNames(selector string, image2 string) bool { |
| 80 | image1 := selector |
| 81 | |
| 82 | // we replace possible # with a's here to avoid an parsing error |
| 83 | // since the tag is stripped anyways it doesn't really matter if we lose |
| 84 | // information where the # were |
| 85 | tagStrippedImage1, _, err := dockerfile.GetStrippedDockerImageName(strings.ReplaceAll(image1, "#", "a")) |
| 86 | if err != nil { |
| 87 | tagStrippedImage1 = image1 |
| 88 | } |
| 89 | tagStrippedImage2, _, err := dockerfile.GetStrippedDockerImageName(image2) |
| 90 | if err != nil { |
| 91 | tagStrippedImage2 = image2 |
| 92 | } |
| 93 | |
| 94 | if tagStrippedImage1 != image1 { |
| 95 | // In the case that the tag is latest and we find an image that has no tag |
| 96 | if tagStrippedImage1+":latest" == image1 && tagStrippedImage2 == image2 { |
| 97 | return true |
| 98 | } |
| 99 | |
| 100 | // if the tag consists of a # we build a regex |
| 101 | if strings.Contains(image1, "#") { |
| 102 | regex := "^" + strings.ReplaceAll(image1, "#", "[a-zA-Z]") + "$" |
| 103 | exp, err := regexp.Compile(regex) |
| 104 | if err == nil { |
| 105 | return exp.MatchString(image2) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return image1 == image2 |
| 110 | } |
| 111 | |
| 112 | return tagStrippedImage1 == tagStrippedImage2 |
| 113 | } |
no test coverage detected