Skip to content

Commit 0a7f7ad

Browse files
committed
Fix dedupe logic to work with compact mode for the purl endpoint
1 parent fab2f79 commit 0a7f7ad

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
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.6"
7+
version = "3.0.7"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',

socketdev/core/dedupe.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def alert_key(alert: dict) -> tuple:
1313
return (
1414
alert["type"],
1515
alert["severity"],
16-
alert["category"],
16+
alert.get("category"),
1717
Dedupe.normalize_file_path(alert.get("file")),
1818
alert.get("start"),
1919
alert.get("end")
@@ -25,7 +25,7 @@ def alert_identity(alert: dict) -> tuple:
2525
return (
2626
alert["type"],
2727
alert["severity"],
28-
alert["category"],
28+
alert.get("category"),
2929
Dedupe.normalize_file_path(alert.get("file")),
3030
alert.get("start"),
3131
alert.get("end")
@@ -39,21 +39,29 @@ def alert_identity(alert: dict) -> tuple:
3939

4040
for alert in pkg.get("alerts", []):
4141
identity = alert_identity(alert)
42-
file = Dedupe.normalize_file_path(alert.get("file"))
4342

4443
if identity not in alert_map:
45-
alert_map[identity] = {
44+
# Build alert dict with only fields that exist in the original alert
45+
consolidated_alert = {
4646
"key": alert["key"], # keep the first key seen
4747
"type": alert["type"],
4848
"severity": alert["severity"],
49-
"category": alert["category"],
50-
"file": file,
51-
"start": alert.get("start"),
52-
"end": alert.get("end"),
5349
"releases": [release],
5450
"props": alert.get("props", []),
5551
"action": alert["action"]
5652
}
53+
54+
# Only include optional fields if they exist in the original alert
55+
if "category" in alert:
56+
consolidated_alert["category"] = alert["category"]
57+
if "file" in alert:
58+
consolidated_alert["file"] = Dedupe.normalize_file_path(alert["file"])
59+
if "start" in alert:
60+
consolidated_alert["start"] = alert["start"]
61+
if "end" in alert:
62+
consolidated_alert["end"] = alert["end"]
63+
64+
alert_map[identity] = consolidated_alert
5765
else:
5866
if release not in alert_map[identity]["releases"]:
5967
alert_map[identity]["releases"].append(release)

socketdev/version.py

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

0 commit comments

Comments
 (0)