diff --git a/swh/indexer/metadata_dictionary/npm.py b/swh/indexer/metadata_dictionary/npm.py --- a/swh/indexer/metadata_dictionary/npm.py +++ b/swh/indexer/metadata_dictionary/npm.py @@ -88,9 +88,15 @@ rdflib.term.URIRef('https://example.org/bugs/') """ if isinstance(d, dict) and isinstance(d.get("url"), str): - return URIRef(d["url"]) + url = d["url"] elif isinstance(d, str): - return URIRef(d) + url = d + else: + url = "" + + parsed_url = urllib.parse.urlparse(url) + if parsed_url.netloc: + return URIRef(url) else: return None diff --git a/swh/indexer/tests/metadata_dictionary/test_npm.py b/swh/indexer/tests/metadata_dictionary/test_npm.py --- a/swh/indexer/tests/metadata_dictionary/test_npm.py +++ b/swh/indexer/tests/metadata_dictionary/test_npm.py @@ -348,7 +348,8 @@ "author": { "name": "foo", "url": "" - } + }, + "bugs": "" }""" result = MAPPINGS["NpmMapping"]().translate(package_json) assert result == { @@ -364,6 +365,9 @@ "author": { "name": "foo", "url": "http:example.com" + }, + "bugs": { + "url": "http:example.com" } }""" result = MAPPINGS["NpmMapping"]().translate(package_json)