Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions capycli/bom/map_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,8 @@ def get_purl_from_match(self, match: Dict[str, Any]) -> str:
"""
raw_purl = ""
if "RepositoryId" in match and match["RepositoryId"]:
return match["RepositoryId"]

if "ExternalIds" in match:
raw_purl = match["RepositoryId"]
elif "ExternalIds" in match:
if "package-url" in match["ExternalIds"]:
raw_purl = match["ExternalIds"]["package-url"]
elif "purl" in match["ExternalIds"]:
Expand All @@ -520,9 +519,9 @@ def get_purl_from_match(self, match: Dict[str, Any]) -> str:

purls = PurlUtils.parse_purls_from_external_id(raw_purl)
if purls:
purl = purls[0]
return purls[0]

return purl
return ""
Comment on lines 520 to +524

def update_bom_item(self, component: Optional[Component], match: Dict[str, Any]) -> Component:
"""Update the (current) SBOM item with values from the match"""
Expand Down
16 changes: 16 additions & 0 deletions tests/test_get_purl_from_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from capycli.bom.map_bom import MapBom


def test_get_purl_from_match_stringified_array() -> None:
mb = MapBom()
# Mocking match with a JSON array string
match = {"RepositoryId": '["pkg:cargo/clap_builder@4.5.60","pkg:cargo/clap@4.5.60"]'}
purl = mb.get_purl_from_match(match)
assert purl == "pkg:cargo/clap_builder@4.5.60"


def test_get_purl_from_match_single_purl() -> None:
mb = MapBom()
match = {"RepositoryId": "pkg:cargo/clap@4.5.60"}
purl = mb.get_purl_from_match(match)
assert purl == "pkg:cargo/clap@4.5.60"