diff --git a/app/utils/license.js b/app/utils/license.js index aa87de46dc1..04427d0e3b1 100644 --- a/app/utils/license.js +++ b/app/utils/license.js @@ -41,14 +41,17 @@ const CAL_LICENSES = [ 'zlib', ]; -const LICENSE_KEYWORDS = new Set(['OR', 'AND', 'WITH']); +const LICENSE_KEYWORDS = new Set(['OR', 'AND', 'WITH', '(', ')']); export function parseLicense(text) { return text .trim() .replace('/', ' OR ') + .replace(/(^\(| \()/, ' ( ') + .replace(/(\)$|\) )/, ' ) ') .replace(/ +/g, ' ') .split(' ') + .filter(Boolean) .map(text => { let lowerCaseText = text.toLowerCase(); diff --git a/tests/utils/license-test.js b/tests/utils/license-test.js index 05e6bac841a..5effafffd25 100644 --- a/tests/utils/license-test.js +++ b/tests/utils/license-test.js @@ -55,6 +55,18 @@ module('parseLicense()', function () { { isKeyword: false, link: undefined, text: 'B' }, ], ], + [ + '(Apache-2.0 OR MIT) AND BSD-3-Clause', + [ + { isKeyword: true, link: undefined, text: '(' }, + { isKeyword: false, link: 'https://choosealicense.com/licenses/apache-2.0', text: 'Apache-2.0' }, + { isKeyword: true, link: undefined, text: 'OR' }, + { isKeyword: false, link: 'https://choosealicense.com/licenses/mit', text: 'MIT' }, + { isKeyword: true, link: undefined, text: ')' }, + { isKeyword: true, link: undefined, text: 'AND' }, + { isKeyword: false, link: 'https://choosealicense.com/licenses/bsd-3-clause', text: 'BSD-3-Clause' }, + ], + ], ]; for (let [input, expectation] of TESTS) {