Skip to content

Commit 3a8b3e8

Browse files
committed
fix: include namespace in deduplicated purl construction
Fix purl deduplication logic to properly handle namespace and inputPurl fields. Previously, Maven packages were missing namespace in the returned purl field. - Use inputPurl when available and complete - Append version to incomplete inputPurl - Construct proper purl with namespace when building from scratch
1 parent 95be734 commit 3a8b3e8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "socketdev"
7-
version = "3.0.0"
7+
version = "3.0.1"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',

socketdev/core/dedupe.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,29 @@ def alert_identity(alert: dict) -> tuple:
6161
base = package_group[0]
6262
base["releases"] = sorted(releases)
6363
base["alerts"] = list(alert_map.values())
64-
base["purl"] = f"pkg:{base.get('type', 'unknown')}/{base.get('name', 'unknown')}@{base.get('version', '0.0.0')}"
64+
65+
# Use inputPurl if available and complete, otherwise construct proper purl with namespace
66+
if "inputPurl" in base and "@" in base["inputPurl"]:
67+
# inputPurl has version, use it as-is
68+
base["purl"] = base["inputPurl"]
69+
else:
70+
# Construct purl properly with namespace and version
71+
purl_type = base.get('type', 'unknown')
72+
namespace = base.get('namespace')
73+
name = base.get('name', 'unknown')
74+
version = base.get('version', '0.0.0')
75+
76+
# Start with inputPurl if available (without version) or construct from scratch
77+
if "inputPurl" in base and not "@" in base["inputPurl"]:
78+
# inputPurl exists but lacks version, append it
79+
base["purl"] = f"{base['inputPurl']}@{version}"
80+
else:
81+
# Construct complete purl from components
82+
if namespace:
83+
base["purl"] = f"pkg:{purl_type}/{namespace}/{name}@{version}"
84+
else:
85+
base["purl"] = f"pkg:{purl_type}/{name}@{version}"
86+
6587
return base
6688

6789
@staticmethod

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.0"
1+
__version__ = "3.0.1"

0 commit comments

Comments
 (0)