Skip to content

Commit a497a89

Browse files
authored
Merge pull request #3351 from nexB/port-v31.2.5-hotfix
Port v31.2.5 hotfix
2 parents 09d9b85 + 0f46f37 commit a497a89

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

CHANGELOG.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,20 @@ License detection:
203203

204204
See https://github.com/nexB/scancode-toolkit/issues/3343
205205

206-
v31.2.5 - 2023-04-21
206+
207+
v31.2.6 - 2023-04-25
208+
----------------------------------
209+
210+
This is a minor hotfix release.
211+
212+
This fix a crash when parsing a .deb Dbeian package filename
213+
reported in https://github.com/nexB/scancode-toolkit/issues/3259
214+
215+
216+
v31.2.5 - 2023-01-09
207217
----------------------------------
208218

209-
This is a minor backport release.
219+
This is a minor fix backport release.
210220

211221
This adds license rule changes and was requested here:
212222
https://github.com/nexB/scancode-toolkit/issues/3310

src/packagedcode/debian.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from debian_inspector.debcon import get_paragraph_data_from_file
1616
from debian_inspector.debcon import get_paragraphs_data_from_file
1717
from debian_inspector.package import DebArchive
18+
from debian_inspector.version import Version as DebVersion
1819
from packageurl import PackageURL
1920

2021
from packagedcode import models
@@ -516,7 +517,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
516517
return models.DatafileHandler.assign_package_to_resources(package, root, codebase, package_adder)
517518

518519

519-
def build_package_data_from_package_filename(filename, datasource_id, package_type,):
520+
def build_package_data_from_package_filename(filename, datasource_id, package_type):
520521
"""
521522
Return a PackageData built from the filename of a Debian package archive.
522523
"""
@@ -529,11 +530,15 @@ def build_package_data_from_package_filename(filename, datasource_id, package_ty
529530
else:
530531
qualifiers = {}
531532

533+
version = deb.version
534+
if isinstance(version, DebVersion):
535+
version = str(version)
536+
532537
return models.PackageData(
533538
datasource_id=datasource_id,
534539
type=package_type,
535540
name=deb.name,
536-
version=deb.version,
541+
version=version,
537542
qualifiers=qualifiers,
538543
)
539544

tests/packagedcode/test_debian.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from scancode.cli_test_utils import check_json_scan
1818
from scancode.cli_test_utils import run_scan_click
1919
from scancode_config import REGEN_TEST_FIXTURES
20+
from packagedcode.debian import build_package_data_from_package_filename
21+
from packagedcode.debian import DebianDebPackageHandler
2022

2123

2224
@skipIf(on_windows, 'These tests contain files that are not legit on Windows.')
@@ -146,3 +148,35 @@ def test_parse_debian_files_list_with_arch(self):
146148

147149
expected_loc = self.get_test_loc('debian/files-md5sums/mokutil-amd64.md5sums.expected.json', must_exist=False)
148150
self.check_packages_data(results, expected_loc, must_exist=False, regen=REGEN_TEST_FIXTURES)
151+
152+
def test_build_package_data_from_package_filename_deb_does_not_crash_on_version(self):
153+
filename = 'libapache2-mod-md_2.4.38-3+deb10u10_amd64.deb'
154+
result = build_package_data_from_package_filename(
155+
filename=filename,
156+
datasource_id='debian_deb',
157+
package_type='deb',
158+
)
159+
assert str(result.purl) == 'pkg:deb/[email protected]%2Bdeb10u10?architecture=amd64'
160+
161+
def test_build_package_data_from_package_filename_orig_sdoes_not_crash_on_version(self):
162+
filename = 'abseil_0~20200923.3.orig.tar.gz'
163+
result = build_package_data_from_package_filename(
164+
filename=filename,
165+
datasource_id='debian_deb',
166+
package_type='deb',
167+
)
168+
assert str(result.purl) == 'pkg:deb/abseil@0~20200923.3'
169+
170+
def test_build_package_data_from_package_filename_debian_tar_sdoes_not_crash_on_version(self):
171+
filename = 'abseil_20220623.1-1.debian.tar.xz'
172+
result = build_package_data_from_package_filename(
173+
filename=filename,
174+
datasource_id='debian_deb',
175+
package_type='deb',
176+
)
177+
assert str(result.purl) == 'pkg:deb/[email protected]'
178+
179+
def test_DebianDebPackageHandler_parse_does_not_crash_on_version(self):
180+
location = 'foo/bar/libapache2-mod-md_2.4.38-3+deb10u10_amd64.deb'
181+
result = list(DebianDebPackageHandler.parse(location))[0]
182+
assert str(result.purl) == 'pkg:deb/[email protected]%2Bdeb10u10?architecture=amd64'

0 commit comments

Comments
 (0)