From c5e2e0c2b80350cf749e1883a226f7af38fe6526 Mon Sep 17 00:00:00 2001 From: Dan Luhring Date: Thu, 22 Jun 2023 14:23:08 -0400 Subject: [PATCH] Fix version detection in Java archive name parsing Signed-off-by: Dan Luhring --- syft/pkg/cataloger/java/archive_filename.go | 4 ++-- syft/pkg/cataloger/java/archive_filename_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/syft/pkg/cataloger/java/archive_filename.go b/syft/pkg/cataloger/java/archive_filename.go index ba8f3b383c5b..084371499d93 100644 --- a/syft/pkg/cataloger/java/archive_filename.go +++ b/syft/pkg/cataloger/java/archive_filename.go @@ -47,8 +47,8 @@ import ( // my-http2-server-5 --> name="my-http2-server", version="5" // jetpack-build235-rc5 --> name="jetpack", version="build2.0-rc5" // ironman-r4-2009 --> name="ironman", version="r4-2009" -var nameAndVersionPattern = regexp.MustCompile(`(?Ui)^(?P(?:[[:alpha:]][[:word:].]*(?:\.[[:alpha:]][[:word:].]*)*-?)+)(?:-(?P(\d.*|(build\d*.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`) -var secondaryVersionPattern = regexp.MustCompile(`(?:[._-](?P(\d.*|(build\d*.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`) +var nameAndVersionPattern = regexp.MustCompile(`(?Ui)^(?P(?:[[:alpha:]][[:word:].]*(?:\.[[:alpha:]][[:word:].]*)*-?)+)(?:-(?P(\d.*|(build\d+.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`) +var secondaryVersionPattern = regexp.MustCompile(`(?:[._-](?P(\d.*|(build\d+.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`) type archiveFilename struct { raw string diff --git a/syft/pkg/cataloger/java/archive_filename_test.go b/syft/pkg/cataloger/java/archive_filename_test.go index 110d94211cee..5752e7d1ad38 100644 --- a/syft/pkg/cataloger/java/archive_filename_test.go +++ b/syft/pkg/cataloger/java/archive_filename_test.go @@ -173,6 +173,13 @@ func TestExtractInfoFromJavaArchiveFilename(t *testing.T) { name: "jboss-saaj-api_1.4_spec", ty: pkg.JavaPkg, }, + { + filename: "/usr/share/java/gradle/lib/gradle-build-cache-8.1.1.jar", + version: "8.1.1", + extension: "jar", + name: "gradle-build-cache", + ty: pkg.JavaPkg, + }, } for _, test := range tests {