Skip to content

Commit

Permalink
fix: improve version detection in Java archive name parsing (#1889)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
  • Loading branch information
luhring authored Jun 22, 2023
1 parent f79cb95 commit 7de7a79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions syft/pkg/cataloger/java/archive_filename.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<name>(?:[[:alpha:]][[:word:].]*(?:\.[[:alpha:]][[:word:].]*)*-?)+)(?:-(?P<version>(\d.*|(build\d*.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`)
var secondaryVersionPattern = regexp.MustCompile(`(?:[._-](?P<version>(\d.*|(build\d*.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`)
var nameAndVersionPattern = regexp.MustCompile(`(?Ui)^(?P<name>(?:[[:alpha:]][[:word:].]*(?:\.[[:alpha:]][[:word:].]*)*-?)+)(?:-(?P<version>(\d.*|(build\d+.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`)
var secondaryVersionPattern = regexp.MustCompile(`(?:[._-](?P<version>(\d.*|(build\d+.*)|(rc?\d+(?:^[[:alpha:]].*)?))))?$`)

type archiveFilename struct {
raw string
Expand Down
7 changes: 7 additions & 0 deletions syft/pkg/cataloger/java/archive_filename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7de7a79

Please sign in to comment.