diff --git a/capycli/bom/map_bom.py b/capycli/bom/map_bom.py index 357ffaab..2235d89f 100644 --- a/capycli/bom/map_bom.py +++ b/capycli/bom/map_bom.py @@ -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"]: @@ -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 "" def update_bom_item(self, component: Optional[Component], match: Dict[str, Any]) -> Component: """Update the (current) SBOM item with values from the match""" diff --git a/tests/test_get_purl_from_match.py b/tests/test_get_purl_from_match.py new file mode 100644 index 00000000..0e70c2a6 --- /dev/null +++ b/tests/test_get_purl_from_match.py @@ -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"