Skip to content

Commit

Permalink
matchers/cargo: Allow SPDX expressions
Browse files Browse the repository at this point in the history
Using a regex that is similar to the one in
lib/licensee/matchers/spdx.rb in allowing spaces and parens.  Parens
aren't currently supported by Cargo's crates.io backing [1,2], but
that's hopefully a temporary limitation.  And Cargo/crates.io already
supports OR forms [3].

Ideally licensee would return the full license expression in these
cases instead of 'other' [4].  But since that conversion is happening
outside the matcher, this commit isn't making that any worse (although
it means this test isn't quite a unit test).

[1]: ehuss/license-exprs#3
[2]: rust-lang/cargo@c89dd64
[3]: rust-lang/cargo#4920
[4]: licensee#244
  • Loading branch information
wking committed Jan 9, 2018
1 parent 3a105b0 commit 87cfeb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/licensee/matchers/cargo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Licensee
module Matchers
class Cargo < Licensee::Matchers::Package
LICENSE_REGEX = %r{
^\s*[\'\"]?license[\'\"]?\s*=\s*[\'\"]([a-z\-0-9\.+\/]+)[\'\"]\s*
^\s*[\'\"]?license[\'\"]?\s*=\s*[\'\"]([a-z\-0-9\. +()\/]+)[\'\"]\s*
}ix

private
Expand Down
18 changes: 10 additions & 8 deletions spec/licensee/matchers/cargo_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
end

{
'spdx name' => ['license = "MIT"', 'mit'],
'single quotes' => ["license = 'mit'", 'mit'],
'quoted key' => ["'license' = 'mit'", 'mit'],
'double quoted key' => ['"license"="mit"', 'mit'],
'no whitespace' => ["license='mit'", 'mit'],
'leading whitespace' => [" license = 'mit'", 'mit'],
'other license' => ['license = "Foo"', 'other'],
'multiple licenses' => ['license = "Apache-2.0/MIT"', 'other']
'spdx name' => ['license = "MIT"', 'mit'],
'single quotes' => ["license = 'mit'", 'mit'],
'quoted key' => ["'license' = 'mit'", 'mit'],
'double quoted key' => ['"license"="mit"', 'mit'],
'no whitespace' => ["license='mit'", 'mit'],
'leading whitespace' => [" license = 'mit'", 'mit'],
'other license' => ['license = "Foo"', 'other'],
'multiple licenses /' => ['license = "Apache-2.0/MIT"', 'other'],
'multiple licenses OR' => ['license = "Apache-2.0 OR MIT"', 'other'],
'multiple licenses parens' => ['license = "(Apache-2.0 OR MIT)"', 'other']
}.each do |description, license_declaration_and_key|
context "with a #{description}" do
let(:content) { license_declaration_and_key[0] }
Expand Down

0 comments on commit 87cfeb4

Please sign in to comment.