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 @@ -272,7 +272,8 @@ return None def normalize_homepage(self, s): - return {"@id": s} + if isinstance(s, str): + return {"@id": s} @register_mapping @@ -515,7 +516,8 @@ return evaluator(tree.body) def normalize_homepage(self, s): - return {"@id": s} + if isinstance(s, str): + return {"@id": s} def normalize_license(self, s): if isinstance(s, str): @@ -528,10 +530,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 @@ -769,6 +769,15 @@ 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.author = "Ruby Coder1", end""" result = MAPPINGS['GemspecMapping'].translate(raw_content) @@ -776,6 +785,16 @@ '@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()