Skip to content

Commit 198f634

Browse files
fix regex
1 parent ac2c414 commit 198f634

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

internal/commands/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2855,7 +2855,7 @@ func validateCreateScanFlags(cmd *cobra.Command) error {
28552855
}
28562856

28572857
func validateContainerImageFormat(containerImage string) error {
2858-
pattern := regexp.MustCompile(`^(?:[a-zA-Z0-9.-]+(?::[0-9]+)?/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$`)
2858+
pattern := regexp.MustCompile(`^(?:[a-zA-Z0-9.-]+(?::[0-9]+)?/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*:[\w][\w.-]{0,127}$`)
28592859

28602860
matched := pattern.MatchString(containerImage)
28612861

internal/commands/scan_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,11 @@ func TestValidateContainerImageFormat(t *testing.T) {
15981598
containerImage: "service.test.whatever.image:8443/service/registries:custom-value",
15991599
expectedError: nil,
16001600
},
1601+
{
1602+
name: "Valid container image format",
1603+
containerImage: "nginx",
1604+
expectedError: errors.Errorf("Invalid value for --container-images flag. The value must be in the format <image-name>:<image-tag>"),
1605+
},
16011606
{
16021607
name: "Missing image name",
16031608
containerImage: ":latest",

0 commit comments

Comments
 (0)