Skip to content

Commit d718ac2

Browse files
fix: ComparablePackageURL includes name (#1022)
Signed-off-by: Arpit Jain <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Jan Kowalleck <[email protected]>
1 parent cb1a4e2 commit d718ac2

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎cyclonedx/_internal/compare.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __new__(cls, p: 'PackageURL') -> 'ComparablePackageURL':
7676
return super().__new__(cls, (
7777
p.type,
7878
p.namespace,
79+
p.name,
7980
p.version,
8081
ComparableDict(p.qualifiers) if isinstance(p.qualifiers, dict) else p.qualifiers,
8182
p.subpath
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file is part of CycloneDX Python Library
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
from unittest import TestCase
19+
20+
from packageurl import PackageURL
21+
22+
from cyclonedx._internal.compare import ComparablePackageURL
23+
24+
25+
class TestComparablePackageURL(TestCase):
26+
27+
def test_differs_by_name(self) -> None:
28+
"""
29+
regression for https://github.com/CycloneDX/cyclonedx-python-lib/issues/1021
30+
31+
name was missing from the comparison tuple, so two purls that differ
32+
only by name compared equal
33+
"""
34+
purl1 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0'))
35+
purl2 = ComparablePackageURL(PackageURL(type='pypi', name='bar', version='1.0.0'))
36+
self.assertNotEqual(purl1, purl2)
37+
self.assertGreater(purl1, purl2)
38+
self.assertLess(purl2, purl1)
39+
40+
def test_equal_same_purl(self) -> None:
41+
purl1 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0'))
42+
purl2 = ComparablePackageURL(PackageURL(type='pypi', name='foo', version='1.0.0'))
43+
self.assertEqual(purl1, purl2)

0 commit comments

Comments
 (0)