Skip to content

Commit a04208f

Browse files
committed
Correctly lowercase purl package names
Some purl types require that package names always be lowercased. This commit fixes certain use cases for a handful of package managers where the purl package names were being improperly reported using uppercase characters. Resolves: #1140 Signed-off-by: Thiéfaine Mercier <[email protected]> Signed-off-by: Rose Judge <[email protected]>
1 parent 1a98be4 commit a04208f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tern/formats/cyclonedx/cyclonedx_common.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,30 @@
4040
]
4141

4242

43+
purl_names_in_lowercase = [
44+
'deb',
45+
'go',
46+
'npm',
47+
'pypi',
48+
'rpm',
49+
]
50+
51+
4352
def get_serial_number():
4453
''' Return a randomly generated CycloneDX BOM serial number '''
4554
return 'urn:uuid:' + str(uuid.uuid4())
4655

4756

57+
def get_purl_name(name, pkg_format):
58+
'''Some purl types require that package names always be lowercased. Given
59+
a package format and a corresponding name for a package of that format,
60+
return a lowercased version of the package name if the purl spec requires
61+
it. Otherwise, just return the original package name.'''
62+
if pkg_format in purl_names_in_lowercase:
63+
return name.lower()
64+
return name
65+
66+
4867
def get_timestamp():
4968
''' Return a timestamp suitable for the BOM timestamp '''
5069
return datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

tern/formats/cyclonedx/cyclonedxjson/package_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def get_package_dict(os_guess, package):
2323
purl_type = package.pkg_format
2424
purl_namespace = cyclonedx_common.get_purl_namespace(os_guess, package.pkg_format)
2525
if purl_type:
26-
purl = PackageURL(purl_type, purl_namespace, package.name, package.version)
26+
purl_name = cyclonedx_common.get_purl_name(package.name,
27+
package.pkg_format)
28+
purl = PackageURL(purl_type, purl_namespace, purl_name, package.version)
2729
package_dict['purl'] = str(purl)
2830

2931
if package.pkg_license:

0 commit comments

Comments
 (0)