diff --git a/swh/model/identifiers.py b/swh/model/identifiers.py index 138ca33a1949dd9d56f6492e1ec987eccd1762fb..934ace85b2bc1a77a0d1fd93ee9e0db5892a40ef 100644 --- a/swh/model/identifiers.py +++ b/swh/model/identifiers.py @@ -702,6 +702,7 @@ def parse_persistent_identifier(persistent_id): key, val = part.split('=') persistent_id_metadata[key] = val except Exception: - pass + msg = 'Contextual data is badly formatted, form key=val expected' + raise SWHMalformedIdentifierException(msg) pid_data.append(persistent_id_metadata) return dict(zip(PERSISTENT_IDENTIFIER_KEYS, pid_data)) diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py index 8282aebb0c4adc0655dcfdf1c727ed2409d08bb9..0cab5003516531d590453bc9dfda4d48a2ec65cb 100644 --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -834,9 +834,7 @@ class SnapshotIdentifier(unittest.TestCase): 'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d', { 'origin': 'deb://Debian/packages/linuxdoc-tools' - }), - ('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;malformed', # noqa - 'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d', {}) + }) ]: expected_result = { 'namespace': 'swh', @@ -858,6 +856,8 @@ class SnapshotIdentifier(unittest.TestCase): 'Wrong format: There should be 4 mandatory parameters'), ('swh:', 'Wrong format: There should be 4 mandatory parameters'), + ('swh:1:cnt:', + 'Wrong format: Identifier should be present'), ('foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505', 'Wrong format: Supported namespace is \'swh\''), ('swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505', @@ -865,8 +865,9 @@ class SnapshotIdentifier(unittest.TestCase): ('swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505', 'Wrong format: Supported types are %s' % ( ', '.join(PERSISTENT_IDENTIFIER_TYPES))), - ('swh:1:cnt:', - 'Wrong format: Identifier should be present'), + ('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;' + 'malformed', + 'Contextual data is badly formatted, form key=val expected') ]: with self.assertRaisesRegex( SWHMalformedIdentifierException, _error):