diff --git a/swh/indexer/metadata_dictionary.py b/swh/indexer/metadata_dictionary.py --- a/swh/indexer/metadata_dictionary.py +++ b/swh/indexer/metadata_dictionary.py @@ -271,7 +271,8 @@ return None def normalize_homepage(self, s): - return {"@id": s} + if isinstance(s, str): + return {"@id": s} @register_mapping @@ -483,7 +484,8 @@ return self.translate_dict(content_dict) def normalize_homepage(self, s): - return {"@id": s} + if isinstance(s, str): + return {"@id": s} def normalize_license(self, s): if isinstance(s, str): @@ -496,10 +498,13 @@ if isinstance(license, str)] def normalize_author(self, author): - return {"@list": [author]} + if isinstance(author, str): + return {"@list": [author]} def normalize_authors(self, authors): - return {"@list": authors} + if isinstance(authors, list): + return {"@list": [author for author in authors + if isinstance(author, str)]} def main(): diff --git a/swh/indexer/tests/test_metadata.py b/swh/indexer/tests/test_metadata.py --- a/swh/indexer/tests/test_metadata.py +++ b/swh/indexer/tests/test_metadata.py @@ -766,6 +766,27 @@ 'type': 'SoftwareSourceCode', }) + def test_gemspec_invalid_author(self): + raw_content = b""" +Gem::Specification.new do |s| + s.author = ["Ruby Coder"] +end""" + result = MAPPINGS['GemspecMapping'].translate(raw_content) + self.assertEqual(result, { + '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', + 'type': 'SoftwareSourceCode', + }) + raw_content = b""" +Gem::Specification.new do |s| + s.authors = ["Ruby Coder1", ["Ruby Coder2"]] +end""" + result = MAPPINGS['GemspecMapping'].translate(raw_content) + self.assertEqual(result, { + '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', + 'type': 'SoftwareSourceCode', + 'author': ['Ruby Coder1'], + }) + def test_revision_metadata_indexer(self): metadata_indexer = RevisionMetadataTestIndexer() fill_obj_storage(metadata_indexer.objstorage)