Skip to content

Commit 7dc5ebe

Browse files
committed
Fixed #433
* problem was caused by the different multi-lic file format between json and CSV (CSV with '\n' line break)
1 parent 561d5cf commit 7dc5ebe

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

docs/CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* Enhance the `transform` to also work with JSON file
55
* Update transform code (See #427 and #428)
66
* Fixed #431 - Error handling for empty "_file" fields
7-
* Fixed #432 - Handled UTF-8 variant invented by Microsoft
7+
* Fixed #432 - Handled UTF-8 variant invented by Microsoft
8+
* Fixed #433 - problem was caused by the different multi-lic file format between json and CSV (CSV with '\n' line break)
89

910
2020-05-05
1011
Release 4.0.2

src/attributecode/model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False, reference_di
990990
# 'Field licenses is a custom field.'
991991
licenses_field = (key, value)
992992
fields.remove(licenses_field)
993-
994993
errors = self.process(
995994
fields=fields,
996995
about_file_path=self.about_file_path,
@@ -1033,7 +1032,12 @@ def dumps(self):
10331032
# Restore the original_value as it was parsed for
10341033
# validation purpose
10351034
if field.original_value:
1036-
license_file = field.original_value.split('\n')
1035+
# This line break is for the components that have multiple license
1036+
# values in CSV format.
1037+
if '\n' in field.original_value:
1038+
license_file = field.original_value.split('\n')
1039+
else:
1040+
license_file = field.value.keys()
10371041
else:
10381042
license_file = field.value.keys()
10391043
elif field.name == 'license_url' and field.value:

tests/test_model.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,37 @@ def test_get_field_names_does_not_return_duplicates_custom_fields(self):
676676
result = model.get_field_names(abouts)
677677
assert expected == result
678678

679+
def test_load_dict_issue_433(self):
680+
package_data = {
681+
'about_resource': 'package1.zip',
682+
'name': 'package',
683+
'version': '1.0',
684+
'copyright': 'copyright on package',
685+
'license_expression': 'license1 AND license2',
686+
'notice_file': 'package1.zip.NOTICE',
687+
'licenses': [
688+
{'key': 'license1', 'name': 'License1', 'file': 'license1.LICENSE'},
689+
{'key': 'license2', 'name': 'License2', 'file': 'license2.LICENSE'},
690+
],
691+
}
692+
about = model.About()
693+
about.load_dict(package_data, base_dir='')
694+
as_dict = about.as_dict()
695+
expected = '''about_resource: package1.zip
696+
name: package
697+
version: '1.0'
698+
license_expression: license1 AND license2
699+
copyright: copyright on package
700+
notice_file: package1.zip.NOTICE
701+
licenses:
702+
- key: license1
703+
name: License1
704+
file: license1.LICENSE
705+
- key: license2
706+
name: License2
707+
file: license2.LICENSE
708+
'''
709+
assert about.dumps() == expected
679710

680711
class SerializationTest(unittest.TestCase):
681712
def test_About_dumps(self):

0 commit comments

Comments
 (0)