diff --git a/lib/license_finder/decisions.rb b/lib/license_finder/decisions.rb index ab2f0af72..290d12de9 100644 --- a/lib/license_finder/decisions.rb +++ b/lib/license_finder/decisions.rb @@ -40,10 +40,15 @@ def approved?(name, version = nil) end def permitted?(lic) - return lic.sub_licenses.any? { |sub_lic| @permitted.include?(sub_lic) } if lic.is_a?(OrLicense) - return lic.sub_licenses.all? { |sub_lic| @permitted.include?(sub_lic) } if lic.is_a?(AndLicense) - - @permitted.include?(lic) + if @permitted.include?(lic) + true + elsif lic.is_a?(OrLicense) + lic.sub_licenses.any? { |sub_lic| @permitted.include?(sub_lic) } + elsif lic.is_a?(AndLicense) + lic.sub_licenses.all? { |sub_lic| @permitted.include?(sub_lic) } + else + false + end end def restricted?(lic) diff --git a/lib/license_finder/license.rb b/lib/license_finder/license.rb index fd2587368..6b2fb0fa3 100644 --- a/lib/license_finder/license.rb +++ b/lib/license_finder/license.rb @@ -19,10 +19,17 @@ def all def find_by_name(name) name ||= 'unknown' - return OrLicense.new(name) if name.include?(OrLicense.operator) - return AndLicense.new(name) if name.include?(AndLicense.operator) - - all.detect { |l| l.matches_name? l.stripped_name(name) } || Definitions.build_unrecognized(name) + license = all.detect { |l| l.matches_name? l.stripped_name(name) } + + if license + license + elsif name.include?(OrLicense.operator) + OrLicense.new(name) + elsif name.include?(AndLicense.operator) + AndLicense.new(name) + else + Definitions.build_unrecognized(name) + end end def find_by_text(text) diff --git a/spec/lib/license_finder/decision_applier_spec.rb b/spec/lib/license_finder/decision_applier_spec.rb index d74901c51..68b79c9d5 100644 --- a/spec/lib/license_finder/decision_applier_spec.rb +++ b/spec/lib/license_finder/decision_applier_spec.rb @@ -268,6 +268,16 @@ module LicenseFinder expect(dep).not_to be_approved expect(dep).not_to be_permitted end + it 'does not mix up with non-compound license with AND' do + dep = Package.new('dep', nil, spec_licenses: ['Common Development and Distribution License 1.0']) + decisions = Decisions.new + .add_package('manual', nil) + .license('manual', 'Common Development and Distribution License 1.0') + .permit('Common Development and Distribution License 1.0') + described_class.new(decisions: decisions, packages: [dep]) + expect(dep).to be_approved + expect(dep).to be_permitted + end end describe 'OR compound licenses' do it 'checks at least one OR condition: success case' do diff --git a/spec/lib/license_finder/license/definitions_spec.rb b/spec/lib/license_finder/license/definitions_spec.rb index 3f4dd7bff..ac980e755 100644 --- a/spec/lib/license_finder/license/definitions_spec.rb +++ b/spec/lib/license_finder/license/definitions_spec.rb @@ -90,7 +90,7 @@ end describe '#matches_text?' do - fit "should return true if the text begins with 'Mozilla Public License Version 1.1'" do + it "should return true if the text begins with 'Mozilla Public License Version 1.1'" do expect(subject).to be_matches_text 'Mozilla Public License Version 1.1' end