Skip to content

Commit b116437

Browse files
committed
cpe: handle uppercase CPEs as well
not quite clear if that's needed for 2.3, but 2.2 is an URI, so the scheme should be handled case insensitive there.
1 parent 9bcb82b commit b116437

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

msys2_devtools/cpe.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CPESpecial(Enum):
1515
def parse_cpe22(cpe: str) -> tuple[CPEValue, CPEValue, CPEValue, CPEValue]:
1616
"""Parse a CPE 2.2 URI"""
1717

18-
if not cpe.startswith("cpe:/"):
18+
if not cpe.lower().startswith("cpe:/"):
1919
raise ValueError("invalid cpe format")
2020
components = []
2121
for part in cpe[5:].split(":"):
@@ -33,7 +33,7 @@ def parse_cpe22(cpe: str) -> tuple[CPEValue, CPEValue, CPEValue, CPEValue]:
3333
def parse_cpe23(cpe: str) -> tuple[CPEValue, CPEValue, CPEValue, CPEValue]:
3434
"""Parse a CPE 2.3 string, also partial CPEs and missing components are treated as ANY."""
3535

36-
if not cpe.startswith("cpe:2.3:"):
36+
if not cpe.lower().startswith("cpe:2.3:"):
3737
raise ValueError("invalid cpe format")
3838

3939
def split_and_unquote(s: str) -> list[CPEValue]:
@@ -80,9 +80,9 @@ def push():
8080
def parse_cpe(cpe: str) -> tuple[CPEValue, CPEValue, CPEValue, CPEValue]:
8181
"""Parse a CPE string into a tuple for the first four components"""
8282

83-
if cpe.startswith("cpe:2.3:"):
83+
if cpe.lower().startswith("cpe:2.3:"):
8484
return parse_cpe23(cpe)
85-
elif cpe.startswith("cpe:/"):
85+
elif cpe.lower().startswith("cpe:/"):
8686
return parse_cpe22(cpe)
8787
else:
8888
raise ValueError("unknown cpe format")

tests/test_cpe.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
def test_parse_cpe_22():
77
assert parse_cpe("cpe:/") == (CPEAny, CPEAny, CPEAny, CPEAny)
8+
assert parse_cpe("CPE:/") == (CPEAny, CPEAny, CPEAny, CPEAny)
89
assert parse_cpe("cpe:/a:cryptopp:crypto%2b%2b:8.9.0") == ("a", "cryptopp", "crypto++", "8.9.0")
910
assert parse_cpe("cpe:/a:cryptopp:crypto%2b%2b") == ("a", "cryptopp", "crypto++", CPEAny)
1011
assert parse_cpe("cpe:/a::crypto%2b%2b") == ("a", CPEAny, "crypto++", CPEAny)
@@ -20,6 +21,7 @@ def test_parse_cpe_23():
2021
assert parse_cpe("cpe:2.3:a:*:bar") == ("a", CPEAny, "bar", CPEAny)
2122
assert parse_cpe("cpe:2.3:a:\\*:bar") == ("a", "*", "bar", CPEAny)
2223
assert parse_cpe("cpe:2.3:a:-:bar") == ("a", CPENA, "bar", CPEAny)
24+
assert parse_cpe("CPE:2.3:a") == ("a", CPEAny, CPEAny, CPEAny)
2325
with pytest.raises(ValueError):
2426
assert parse_cpe("cpe:2.3:a::") == ("a", "", "", CPEAny)
2527
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)