Skip to content

Commit ca4a246

Browse files
fix: account for N plus signs in rpm release string
Also, add more test cases from different distros. Signed-off-by: Will Murphy <[email protected]>
1 parent 6836892 commit ca4a246

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

grype/version/rpm_version.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,11 @@ func compareRpmReleases(a, b string) int {
116116
return 0
117117
}
118118

119-
aParts := strings.Split(a, "+")
120-
bParts := strings.Split(b, "+")
121-
if len(aParts) > 2 {
122-
aParts = aParts[:len(aParts)-2]
123-
}
124-
if len(bParts) > 2 {
125-
bParts = bParts[:len(bParts)-2]
126-
}
127-
trimmedA := strings.Join(aParts, "+")
128-
trimmedB := strings.Join(bParts, "+")
119+
a = strings.Replace(a, "module+el", "module_el", 1)
120+
b = strings.Replace(b, "module+el", "module_el", 1)
121+
122+
trimmedA, _, _ := strings.Cut(a, "+")
123+
trimmedB, _, _ := strings.Cut(b, "+")
129124
return compareRpmVersions(trimmedA, trimmedB)
130125
}
131126

grype/version/rpm_version_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func TestVersionRpm(t *testing.T) {
3434
// centos and rhel build numbers differ on same version of same package
3535
// ensure these are equal.
3636
{"3:10.3.28-1.module_el8.3.0+757+d382997d", "3:10.3.28-1.module+el8.3.0+10472+7adc332a", 0},
37+
// some amazonlinux examples
38+
{"2.13.0-2.amzn2023.0.2", "2.13.0-2.amzn2023.0.1", 1},
39+
{"1.20.14-18.amzn2023.0.1", "1.20.14-18.amzn2023.0.2", -1},
40+
// examples from oracle linux 8 for python38-tkinter ELSA-2021-9130
41+
{"3.8.17-2.module+el8.9.0+90017+9913aa0c", "0:3.8.3-3.0.1.module+el8.3.0+el8+9681+09f2c1ca", 1},
42+
// note that build number 9680 and 9681 are different, but that's not part of the version comparison
43+
{"0:3.8.3-3.0.1.module+el8.3.0+el8+9680+09f2c1ca", "0:3.8.3-3.0.1.module+el8.3.0+el8+9681+09f2c1ca", 0},
3744
}
3845

3946
for _, test := range tests {

0 commit comments

Comments
 (0)