Skip to content

Commit 26a9160

Browse files
author
b31ngd3v
committed
refactor: no need for custom get_version func
1 parent e8eb064 commit 26a9160

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

cve_bin_tool/checkers/commons_compress.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
88
https://www.cvedetails.com/vulnerability-list/vendor_id-45/product_id-59066/Apache-Commons-Compress.html
99
"""
10-
import re
11-
1210
from cve_bin_tool.checkers import Checker
13-
from cve_bin_tool.util import regex_find
1411

1512

1613
class CommonsCompressChecker(Checker):
@@ -20,29 +17,6 @@ class CommonsCompressChecker(Checker):
2017
]
2118
FILENAME_PATTERNS = [r"commons-compress(-[0-9]+\.[0-9]+(\.[0-9]+)?)?.jar"]
2219
VERSION_PATTERNS = [
23-
r"<artifactId>commons-compress-([0-9]+\.[0-9]+(\.[0-9]+)?)</artifactId>"
20+
r"<artifactId>commons-compress</artifactId>\n <version>([0-9]+\.[0-9]+(\.[0-9]+)?)</version>"
2421
]
2522
VENDOR_PRODUCT = [("apache", "commons_compress")]
26-
27-
def get_version(self, lines, filename):
28-
version_info = super().get_version(lines, filename)
29-
lines = lines.split("\n")
30-
31-
index_value = [
32-
i
33-
for i, line in enumerate(lines)
34-
if re.search("<artifactId>commons-compress</artifactId>", line)
35-
]
36-
37-
if not index_value:
38-
return version_info
39-
else:
40-
index_value = index_value[0]
41-
42-
version_string = lines[index_value + 1]
43-
version_pattern = [r"<version>([0-9]+\.[0-9]+(\.[0-9]+)?)</version>"]
44-
version_regex = list(map(re.compile, version_pattern))
45-
new_version = regex_find(version_string, version_regex)
46-
version_info["version"] = new_version
47-
48-
return version_info

test/test_data/commons_compress.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
{
66
"product": "commons_compress",
77
"version": "1.18",
8-
"version_strings": ["<artifactId>commons-compress-1.18</artifactId>"],
8+
"version_strings": [
9+
"<artifactId>commons-compress</artifactId>\n <version>1.18</version>"
10+
],
11+
},
12+
{
13+
"product": "commons_compress",
14+
"version": "1.15.1",
15+
"version_strings": [
16+
"<artifactId>commons-compress</artifactId>\n <version>1.15.1</version>"
17+
],
918
},
1019
]
1120
package_test_data = [

0 commit comments

Comments
 (0)