Skip to content

Commit da8d06e

Browse files
committed
fix: Limit multiple license splits to SPDX OR
The previous implementation split on a lowercase ` or ` which broke several licenses in the GPL family. This commit fixes that by only splitting on SPDX ` OR ` (including surrounding spaces) which is case sensitive. fixes #101
1 parent 32d9a29 commit da8d06e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

liccheck/command_line.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,9 @@ def check_one(license_str, license_rule="AUTHORIZED", as_regex=False):
262262
def get_license_names(licenses):
263263
names = []
264264
for license in licenses:
265-
license = license.lower()
266-
options = license.split(" or ")
265+
options = license.split(" OR ")
267266
for option in options:
268-
names.append(option)
267+
names.append(option.lower())
269268
return names
270269

271270
def find_parents(package, all, seen):

tests/test_check_package.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def packages():
2828
{
2929
"name": "auth_one_or_unauth_one",
3030
"version": "2",
31-
"licenses": ["authorized 1 or unauthorized 1"],
31+
"licenses": ["authorized 1 OR unauthorized 1"],
3232
},
3333
{
3434
"name": "unauth_one",
@@ -57,6 +57,12 @@ def packages():
5757
},
5858
]
5959

60+
def strategy_with_one_auth(license):
61+
return Strategy(
62+
authorized_licenses=[license.lower()],
63+
unauthorized_licenses=[],
64+
authorized_packages={},
65+
)
6066

6167
@pytest.mark.parametrize(
6268
("strategy_params", "as_regex"),
@@ -92,3 +98,33 @@ def test_check_package(strategy_params, packages, level, reasons, as_regex):
9298
strategy = Strategy(**strategy_params)
9399
for package, reason in zip(packages, reasons):
94100
assert check_package(strategy, package, level, as_regex) is reason
101+
102+
@pytest.mark.parametrize(
103+
"license", [
104+
"GNU Library or Lesser General Public License (LGPL)",
105+
"GNU Lesser General Public License v2 or later (LGPLv2+)"
106+
]
107+
)
108+
def test_check_package_respects_licences_with_a_lowercase_or(license):
109+
strategy = strategy_with_one_auth(license)
110+
package = {
111+
"name": "lgpl_example",
112+
"version": "2",
113+
"licenses": [license],
114+
}
115+
assert check_package(strategy, package, Level.STANDARD, False) is OK
116+
117+
def test_check_package_splits_licenses_with_SPDX_OR():
118+
# The SPDX standard allows packages to specific dual licenses with an OR operator.
119+
# See https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60
120+
mit_strategy = strategy_with_one_auth("MIT")
121+
apache_strategy = strategy_with_one_auth("Apache-2.0")
122+
gpl_strategy = strategy_with_one_auth("GPL-2.0-or-later")
123+
package = {
124+
"name": "mit_example",
125+
"version": "2",
126+
"licenses": ["MIT OR Apache-2.0"],
127+
}
128+
assert check_package(mit_strategy, package, Level.STANDARD, False) is OK
129+
assert check_package(apache_strategy, package, Level.STANDARD, False) is OK
130+
assert check_package(gpl_strategy, package, Level.STANDARD, False) is UNKNOWN

0 commit comments

Comments
 (0)