Skip to content

Commit

Permalink
handle tilde in version string
Browse files Browse the repository at this point in the history
Signed-off-by: Benji Visser <[email protected]>
  • Loading branch information
noqcks committed Jan 9, 2024
1 parent d1780ef commit ef6ae37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xeol/search/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func normalizeSemver(version string) string {
// Example: 5.0.20.5194 -> 5.0.20
// Example: 2.0.4.RELEASE -> 2.0.4
fourCompRe := regexp.MustCompile(`^(\d+\.\d+\.\d+)\.\w+`)
return fourCompRe.ReplaceAllString(version, "$1")
version = fourCompRe.ReplaceAllString(version, "$1")

// // Handle packages with tilde (~) characters
// // Example: 1.23.3-1~bullseye
tildeRe := regexp.MustCompile(`^(\d+\.\d+\.\d+)-\d+~\w+`)
return tildeRe.ReplaceAllString(version, "$1")
}

func versionLength(version string) int {
Expand Down
4 changes: 4 additions & 0 deletions xeol/search/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func TestNormalizeSemver(t *testing.T) {
version string
expected string
}{
{
version: "1.23.3-1~bullseye",
expected: "1.23.3",
},
{
version: "2.0.4.RELEASE",
expected: "2.0.4",
Expand Down

0 comments on commit ef6ae37

Please sign in to comment.