Skip to content

Commit

Permalink
TagsCheck: handle license exception in grouping
Browse files Browse the repository at this point in the history
A valid license exception which is in a grouping is reported as invalid.
This is due to the trailing ')' being included in the regex.  The
following license:

    (GPL-2.0-only OR GPL-3.0-only WITH Qt-GPL-exception-1.0) AND MIT

returns:

    W: invalid-license-exception Qt-GPL-exception-1.0)

Adjust the license_exception_regex to exclude trailing parenthesis.

Fixes: https://bugzilla.redhat.com/2175241
  • Loading branch information
tmzullinger committed Mar 3, 2023
1 parent abc2f03 commit 7d707f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpmlint/checks/TagsCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
leading_space_regex = re.compile(r'^\s+')
pkg_config_regex = re.compile(r'^/usr/(?:lib\d*|share)/pkgconfig/')
license_regex = re.compile(r'\(([^)]+)\)|\s(?:and|or|AND|OR)\s')
license_exception_regex = re.compile(r'(\S+)\s(?:WITH|with)\s(\S+)')
license_exception_regex = re.compile(r'(\S+)\s(?:WITH|with)\s([^)]+)')
invalid_version_regex = re.compile(r'([0-9](?:rc|alpha|beta|pre).*)', re.IGNORECASE)
# () are here for grouping purpose in the regexp
tag_regex = re.compile(r'^((?:Auto(?:Req|Prov|ReqProv)|Build(?:Arch(?:itectures)?|Root)|(?:Build)?Conflicts|(?:Build)?(?:Pre)?Requires|Copyright|(?:CVS|SVN)Id|Dist(?:ribution|Tag|URL)|DocDir|(?:Build)?Enhances|Epoch|Exclu(?:de|sive)(?:Arch|OS)|Group|Icon|License|Name|No(?:Patch|Source)|Obsoletes|Packager|Patch\d*|Prefix(?:es)?|Provides|(?:Build)?Recommends|Release|RHNPlatform|Serial|Source\d*|(?:Build)?Suggests|Summary|(?:Build)?Supplements|(?:Bug)?URL|Vendor|Version)(?:\([^)]+\))?:)\s*\S', re.IGNORECASE)
Expand Down
Binary file not shown.
12 changes: 12 additions & 0 deletions test/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def test_valid_license_exception(tmpdir, package, tagscheck):
assert 'W: invalid-license-exception' not in out


@pytest.mark.parametrize('package', ['source/valid-exception-in-grouping'])
def test_valid_license_exception_in_grouping(tmpdir, package, tagscheck):
CONFIG.info = True
CONFIG.configuration['ValidLicenses'] = ['BSD-3-Clause', 'GPL-2.0-only']
CONFIG.configuration['ValidLicenseExceptions'] = ['Qt-GPL-exception-1.0']
output = Filter(CONFIG)
test = TagsCheck(CONFIG, output)
test.check(get_tested_package(package, tmpdir))
out = output.print_results(output.results)
assert 'W: invalid-license-exception' not in out


@pytest.mark.parametrize('package', ['binary/xtables-addons-kmp-default'])
def test_forbidden_controlchar_found_requires(tmpdir, package, tagscheck):
output, test = tagscheck
Expand Down

0 comments on commit 7d707f7

Please sign in to comment.