Skip to content

Commit 5da315e

Browse files
committed
Fixed #442
No special characters are allowed for license_key, license_name and license_expression
1 parent 2835675 commit 5da315e

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

SPECIFICATION.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ABOUT File Specification v3.1.5
1+
ABOUT File Specification v3.2.0
22

33

44
Purpose
@@ -323,11 +323,11 @@ Optional Licensing fields
323323
- license_expression: The DejaCode license expression that apply to the component. You
324324
can separate each identifier using " or " and " and " to document the
325325
relationship between multiple license identifiers, such as a choice among
326-
multiple licenses.
326+
multiple licenses (No special characters are allowed).
327327

328-
- license_name: The DejaCode license short name for the license.
328+
- license_name: The DejaCode license short name for the license (No special characters are allowed).
329329

330-
- license_key: The DejaCode license key(s) for the component.
330+
- license_key: The DejaCode license key(s) for the component (No special characters are allowed).
331331

332332

333333
Optional Boolean flag fields

src/attributecode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
__version__ = '5.0.0'
3535

36-
__about_spec_version__ = '3.1.4'
36+
__about_spec_version__ = '3.2.0'
3737

3838
__copyright__ = """
3939
Copyright (c) 2013-2020 nexB Inc. All rights reserved. http://dejacode.org

src/attributecode/cmd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def inventory(location, output, format, quiet, verbose): # NOQA
185185
errors, abouts = collect_inventory(location)
186186
write_errors = write_output(abouts=abouts, location=output, format=format)
187187
errors.extend(write_errors)
188+
errors = unique(errors)
188189
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
189190
if not quiet:
190191
msg = 'Inventory collected in {output}.'.format(**locals())
@@ -262,6 +263,7 @@ def gen(location, output, android, fetch_license, reference, quiet, verbose):
262263
fetch_license=fetch_license,
263264
)
264265

266+
errors = unique(errors)
265267
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
266268
if not quiet:
267269
abouts_count = len(abouts)
@@ -351,7 +353,7 @@ def attrib(location, output, template, vartext, quiet, verbose):
351353
variables=vartext,
352354
)
353355
errors.extend(attrib_errors)
354-
356+
errors = unique(errors)
355357
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
356358

357359
if not quiet:
@@ -391,6 +393,7 @@ def check(location, verbose):
391393
print_version()
392394
click.echo('Checking ABOUT files...')
393395
errors, _abouts = collect_inventory(location)
396+
errors = unique(errors)
394397
severe_errors_count = report_errors(errors, quiet=False, verbose=verbose)
395398
sys.exit(severe_errors_count)
396399

@@ -475,6 +478,7 @@ def transform(location, output, configuration, quiet, verbose): # NOQA
475478
print_version()
476479
click.echo('Transforming...')
477480

481+
errors = unique(errors)
478482
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
479483
if not quiet and not errors:
480484
msg = 'Transformed file written to {output}.'.format(**locals())

src/attributecode/model.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ class StringField(Field):
239239
"""
240240
def _validate(self, *args, **kwargs):
241241
errors = super(StringField, self)._validate(*args, ** kwargs)
242+
no_special_char_field = ['license_expression', 'license_key', 'license_name']
243+
name = self.name
244+
if name in no_special_char_field:
245+
val = self.value
246+
special_char = detect_special_char(val)
247+
if special_char:
248+
msg = (u'The following character(s) cannot be in the %(name)s: '
249+
'%(special_char)r' % locals())
250+
errors.append(Error(ERROR, msg))
242251
return errors
243252

244253
def _serialized_value(self):
@@ -1388,7 +1397,7 @@ def pre_process_and_fetch_license_dict(abouts, api_url, api_key):
13881397
if about.license_expression.present:
13891398
special_char_in_expression, lic_list = parse_license_expression(about.license_expression.value)
13901399
if special_char_in_expression:
1391-
msg = (u"The following character(s) cannot be in the licesne_expression: " +
1400+
msg = (u"The following character(s) cannot be in the license_expression: " +
13921401
str(special_char_in_expression))
13931402
errors.append(Error(ERROR, msg))
13941403
else:
@@ -1412,20 +1421,20 @@ def pre_process_and_fetch_license_dict(abouts, api_url, api_key):
14121421
def parse_license_expression(lic_expression):
14131422
licensing = Licensing()
14141423
lic_list = []
1415-
special_char = special_char_in_license_expresion(lic_expression)
1424+
special_char = detect_special_char(lic_expression)
14161425
if not special_char:
14171426
# Parse the license expression and save it into a list
14181427
lic_list = licensing.license_keys(lic_expression)
14191428
return special_char, lic_list
14201429

14211430

1422-
def special_char_in_license_expresion(lic_expression):
1431+
def detect_special_char(expression):
14231432
not_support_char = [
14241433
'!', '@', '#', '$', '%', '^', '&', '*', '=', '{', '}',
14251434
'|', '[', ']', '\\', ':', ';', '<', '>', '?', ',', '/']
14261435
special_character = []
14271436
for char in not_support_char:
1428-
if char in lic_expression:
1437+
if char in expression:
14291438
special_character.append(char)
14301439
return special_character
14311440

tests/test_model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,12 @@ def test_get_field_names_does_not_return_duplicates_custom_fields(self):
685685
result = model.get_field_names(abouts)
686686
assert expected == result
687687

688+
def test_comma_in_license(self):
689+
test_file = get_test_loc('test_model/special_char/about.ABOUT')
690+
a = model.About(test_file)
691+
expected = Error(ERROR, "The following character(s) cannot be in the license_key: [',']")
692+
assert a.errors[0] == expected
693+
688694
def test_load_dict_issue_433(self):
689695
package_data = {
690696
'about_resource': 'package1.zip',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
about_resource: .
2+
3+
name: AboutCode
4+
version: 0.11.0
5+
6+
license_key: mit, gpl-2.0

0 commit comments

Comments
 (0)