Skip to content

Commit

Permalink
make normalizeSemver handle 4 component versions (#198)
Browse files Browse the repository at this point in the history
Signed-off-by: Benji Visser <benji@093b.org>
  • Loading branch information
noqcks authored Oct 6, 2023
1 parent 902de69 commit c815e65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion xeol/search/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ func ByDistroCpe(store eol.Provider, distro *linux.Release, eolMatchDate time.Ti
func normalizeSemver(version string) string {
// For Ruby versions. Example: 2.5.3p105 -> 2.5.3
re := regexp.MustCompile(`^(\d+\.\d+\.\d+)p\d+`)
return re.ReplaceAllString(version, "$1")
version = re.ReplaceAllString(version, "$1")

// Handle 4-component versions.
// 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")
}

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

0 comments on commit c815e65

Please sign in to comment.