license expression in package.json obtains other rather than nil

https://docs.npmjs.com/files/package.json#license can be a SPDX
license expression rather than a SPDX license id. If expression
found, makes sense to return other license rather than nil from
package. So add space, plus, and parens to character class match
as those can be part of a license expression.
This commit is contained in:
Mike Linksvayer 2017-11-22 14:25:29 -08:00
parent 00489bb3bf
commit a6cfb6bd35
3 changed files with 16 additions and 1 deletions

View File

@ -4,7 +4,7 @@ module Licensee
# While we could parse the package.json or bower.json file, prefer # While we could parse the package.json or bower.json file, prefer
# a lenient regex for speed and security. Moar parsing moar problems. # a lenient regex for speed and security. Moar parsing moar problems.
LICENSE_REGEX = / LICENSE_REGEX = /
\s*[\"\']license[\"\']\s*\:\s*[\'\"]([a-z\-0-9\.]+)[\'\"],?\s* \s*[\"\']license[\"\']\s*\:\s*[\'\"]([a-z\-0-9\.+ ()]+)[\'\"],?\s*
/ix /ix
private private

View File

@ -0,0 +1,6 @@
{
"name": "fake-package"
"description": "Fake package available under various licenses",
"license": "(MIT OR Apache-2.0 OR AGPL-3.0+)",
"version": "0.1"
}

View File

@ -177,6 +177,15 @@ RSpec.describe 'integration test' do
expect(subject.license).to eql(license) expect(subject.license).to eql(license)
end end
end end
context 'with package.json license expression' do
let(:fixture) { 'npm-license-expression' }
let(:arguments) { { detect_packages: true } }
it 'matches other' do
expect(subject.license).to eql(other_license)
end
end
end end
context 'with the license file stubbed' do context 'with the license file stubbed' do