From 970d19202d13d4becbbf040b3a9fb115dd7a0795 Mon Sep 17 00:00:00 2001 From: Paul Horton Date: Tue, 12 Oct 2021 15:23:01 +0100 Subject: [PATCH] fix: multiple hashes being created for an externalRefernce which is not as required Signed-off-by: Paul Horton --- cyclonedx/model/__init__.py | 7 +++++-- tests/test_parser_pipenv.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cyclonedx/model/__init__.py b/cyclonedx/model/__init__.py index 2c62ac56..282cdd91 100644 --- a/cyclonedx/model/__init__.py +++ b/cyclonedx/model/__init__.py @@ -150,11 +150,14 @@ class ExternalReference: _hashes: List[HashType] = [] def __init__(self, reference_type: ExternalReferenceType, url: str, comment: str = None, - hashes: List[HashType] = []): + hashes: List[HashType] = None): self._reference_type = reference_type self._url = url self._comment = comment - self._hashes = hashes + if not hashes: + self._hashes.clear() + else: + self._hashes = hashes def add_hash(self, our_hash: HashType): """ diff --git a/tests/test_parser_pipenv.py b/tests/test_parser_pipenv.py index be139718..fb4904c3 100644 --- a/tests/test_parser_pipenv.py +++ b/tests/test_parser_pipenv.py @@ -34,3 +34,4 @@ def test_simple(self): self.assertEqual('toml', components[0].get_name()) self.assertEqual('0.10.2', components[0].get_version()) self.assertEqual(len(components[0].get_external_references()), 2) + self.assertEqual(len(components[0].get_external_references()[0].get_hashes()), 1)