Skip to content

Commit 80ecd35

Browse files
Merge pull request #3279 from vargenau/add-sha1-for-empty-file
Fix #3250: Invalid SPDX with empty file: no SHA1
2 parents 95a5f33 + d7e8318 commit 80ecd35

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following organizations or individuals have contributed to ScanCode:
4444
- Lemo Shi @lemoshi
4545
- Li Ha @linexb
4646
- Mankaran Singh @MankaranSingh
47+
- Marc-Etienne Vargenau @vargenau
4748
- Martin Petkov @MartinPetkov
4849
- Maximilian Huber @maxhbr
4950
- Michael Herzog @mjherzog

src/formattedcode/output_spdx.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ def write_spdx(
288288
file_entry = File(
289289
spdx_id=f'SPDXRef-{sid}',
290290
name=name)
291-
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, file_data.get('sha1') or ''))
291+
if file_data.get('file_type') == 'empty':
292+
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, "da39a3ee5e6b4b0d3255bfef95601890afd80709"))
293+
else:
294+
file_entry.set_checksum(Checksum(ChecksumAlgorithm.SHA1, file_data.get('sha1') or ''))
292295

293296
file_license_detections = file_data.get('license_detections')
294297
license_matches = get_matches_from_detection_mappings(file_license_detections)

tests/formattedcode/test_output_spdx.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,18 @@ def test_output_spdx_rdf_can_handle_non_ascii_paths():
346346
results = res.read()
347347
assert 'han/据.svg' in results
348348

349-
350349
def test_output_spdx_tv_can_handle_non_ascii_paths():
351350
test_file = test_env.get_test_loc('spdx/unicode.json')
352351
result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx')
353352
run_scan_click(['--from-json', test_file, '--spdx-tv', result_file])
354353
with io.open(result_file, encoding='utf-8') as res:
355354
results = res.read()
356355
assert 'han/据.svg' in results
356+
357+
def test_output_spdx_tv_sh1_of_empty_file():
358+
test_dir = test_env.get_test_loc('spdx/empty/scan/somefile')
359+
result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx')
360+
run_scan_click([test_dir, '-clip', '--spdx-tv', result_file])
361+
with io.open(result_file, encoding='utf-8') as res:
362+
results = res.read()
363+
assert 'FileChecksum: SHA1: da39a3ee5e6b4b0d3255bfef95601890afd80709' in results

0 commit comments

Comments
 (0)