Skip to content

Commit f8cf16c

Browse files
authored
Merge pull request #529 from snyk/fix/dashes
fix: identify correclty image names that contains dashes
2 parents 7c81153 + 1bd5f95 commit f8cf16c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/scanner/images/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function removePulledImages(images: IPullableImage[]): Promise<void
4343
// Exported for testing
4444
export function getImageParts(imageWithTag: string) : {imageName: string, imageTag: string} {
4545
// we're matching pattern: <registry:port_number>(optional)/<image_name>(mandatory)@<tag_identifier>(optional):<image_tag>(optional)
46-
const regex = /((?:.*(:\d{4})?\/)?(?:[a-z0-9]+))([@|:].+)?/ig;
46+
const regex = /((?:.*(:\d{4})?\/)?(?:[a-z0-9-]+))([@|:].+)?/ig;
4747
const groups = regex.exec(imageWithTag);
4848

4949
if(!groups){

test/unit/scanner/images.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ tap.test('extracted image tag tests', async (t) => {
8585
});
8686

8787
tap.test('extracted image name tests', async (t) => {
88-
t.plan(4);
88+
t.plan(5);
8989

9090
t.same(scannerImages.getImageParts('nginx:latest').imageName, 'nginx', 'removed image:tag');
9191
t.same(scannerImages.getImageParts('nginx:@sha256:1234567890abcdef').imageName, 'nginx', 'removed malformed image:@sha:hex');
9292
t.same(scannerImages.getImageParts('node@sha256:215a9fbef4df2c1ceb7c79481d3cfd94ad8f1f0105bade39f3be907bf386c5e1').imageName, 'node', 'removed image@sha:hex');
9393
t.same(scannerImages.getImageParts('kind-registry:5000/python:rc-buster').imageName, 'kind-registry:5000/python', 'removed repository/image:tag');
94+
// Verify support on image names that contain dashes
95+
t.same(scannerImages.getImageParts('kind-registry:5000/python-27:rc-buster').imageName, 'kind-registry:5000/python-27', 'removed repository/image:tag');
9496
});

0 commit comments

Comments
 (0)