Skip to content

Commit

Permalink
[Fixed] Ensure licenses are recognised by spdx_id
Browse files Browse the repository at this point in the history
The recognition of licenses named by their SPDX ID is currently
inconsistent; for some licenses the ID is included as an alternative
name, but for some it is not. This leads to inconsistent behaviour, as
seen in issue #984.

Changing the matching logic to check the SPDX ID will make this more
consistent and intuitive.

This fixes #984
  • Loading branch information
swarren12 committed Jul 9, 2023
1 parent 5252cfc commit b263f50
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/license_finder/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def unrecognized_matcher?
attr_reader :short_name, :pretty_name, :other_names, :spdx_id, :matcher

def names
([short_name, pretty_name] + other_names).uniq
([short_name, pretty_name, spdx_id] + other_names).uniq
end
end

Expand Down
22 changes: 6 additions & 16 deletions lib/license_finder/license/definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,19 @@ def build_unrecognized(name)
def apache1_1
License.new(
short_name: 'Apache1_1',
pretty_name: 'Apache 1.1',
spdx_id: 'Apache-1.1',
other_names: [
'Apache-1.1',
'The Apache Software License, Version 1.1'
],
pretty_name: 'Apache 1.1',
other_names: ['Apache Software License, Version 1.1'],
url: 'http://www.apache.org/licenses/LICENSE-1.1.txt'
)
end

def apache2
License.new(
short_name: 'Apache2',
pretty_name: 'Apache 2.0',
spdx_id: 'Apache-2.0',
pretty_name: 'Apache 2.0',
other_names: [
'Apache-2.0',
'Apache Software License',
'Apache License 2.0',
'Apache License Version 2.0',
Expand All @@ -83,7 +79,7 @@ def bsd
License.new(
short_name: 'BSD',
spdx_id: 'BSD-4-Clause',
other_names: ['BSD4', 'bsd-old', '4-clause BSD', 'BSD-4-Clause', 'BSD 4-Clause', 'BSD License'],
other_names: ['BSD4', 'bsd-old', '4-clause BSD', 'BSD 4-Clause', 'BSD License'],
url: 'http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29'
)
end
Expand Down Expand Up @@ -118,7 +114,6 @@ def eclipse1
spdx_id: 'EPL-1.0',
pretty_name: 'Eclipse Public License 1.0',
other_names: [
'EPL-1.0',
'EPL 1.0',
'Eclipse Public License - v 1.0'
],
Expand Down Expand Up @@ -167,7 +162,6 @@ def lgpl2_1
spdx_id: 'LGPL-2.1-only',
pretty_name: 'GNU Lesser General Public License version 2.1',
other_names: [
'LGPL-2.1-only',
'LGPL 2.1',
'LGPL v2.1',
'GNU Lesser General Public License 2.1'
Expand All @@ -191,7 +185,7 @@ def mit
License.new(
short_name: 'MIT',
spdx_id: 'MIT',
other_names: ['Expat', 'MIT license', 'MIT License', 'The MIT License (MIT)'],
other_names: ['Expat', 'MIT license', 'MIT License (MIT)'],
url: 'http://opensource.org/licenses/mit-license',
matcher: matcher
)
Expand All @@ -213,7 +207,6 @@ def mpl1_1
spdx_id: 'MPL-1.1',
pretty_name: 'Mozilla Public License 1.1',
other_names: [
'MPL-1.1',
'Mozilla Public License, Version 1.1',
'Mozilla Public License version 1.1'
],
Expand All @@ -235,7 +228,6 @@ def mpl2
spdx_id: 'MPL-2.0',
pretty_name: 'Mozilla Public License 2.0',
other_names: [
'MPL-2.0',
'Mozilla Public License, Version 2.0',
'Mozilla Public License version 2.0'
],
Expand Down Expand Up @@ -267,7 +259,6 @@ def newbsd
'BSD-3',
'3-clause BSD',
'3-Clause BSD License',
'BSD-3-Clause',
'BSD 3-Clause',
'BSD 3-Clause License',
'The 3-Clause BSD License',
Expand Down Expand Up @@ -332,9 +323,8 @@ def simplifiedbsd
other_names: [
'FreeBSD',
'2-clause BSD',
'BSD-2-Clause',
'BSD 2-Clause',
'The BSD 2-Clause License'
'BSD 2-Clause License'
],
url: 'http://opensource.org/licenses/bsd-license'
)
Expand Down
Loading

0 comments on commit b263f50

Please sign in to comment.