Skip to content

Commit 0d1a444

Browse files
committed
utils/license: Add support for parentheses
1 parent 2c71b2a commit 0d1a444

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/utils/license.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ const CAL_LICENSES = [
4141
'zlib',
4242
];
4343

44-
const LICENSE_KEYWORDS = new Set(['OR', 'AND', 'WITH']);
44+
const LICENSE_KEYWORDS = new Set(['OR', 'AND', 'WITH', '(', ')']);
4545

4646
export function parseLicense(text) {
4747
return text
4848
.trim()
4949
.replace('/', ' OR ')
50+
.replace(/(^\(| \()/, ' ( ')
51+
.replace(/(\)$|\) )/, ' ) ')
5052
.replace(/ +/g, ' ')
5153
.split(' ')
54+
.filter(Boolean)
5255
.map(text => {
5356
let lowerCaseText = text.toLowerCase();
5457

tests/utils/license-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ module('parseLicense()', function () {
5555
{ isKeyword: false, link: undefined, text: 'B' },
5656
],
5757
],
58+
[
59+
'(Apache-2.0 OR MIT) AND BSD-3-Clause',
60+
[
61+
{ isKeyword: true, link: undefined, text: '(' },
62+
{ isKeyword: false, link: 'https://choosealicense.com/licenses/apache-2.0', text: 'Apache-2.0' },
63+
{ isKeyword: true, link: undefined, text: 'OR' },
64+
{ isKeyword: false, link: 'https://choosealicense.com/licenses/mit', text: 'MIT' },
65+
{ isKeyword: true, link: undefined, text: ')' },
66+
{ isKeyword: true, link: undefined, text: 'AND' },
67+
{ isKeyword: false, link: 'https://choosealicense.com/licenses/bsd-3-clause', text: 'BSD-3-Clause' },
68+
],
69+
],
5870
];
5971

6072
for (let [input, expectation] of TESTS) {

0 commit comments

Comments
 (0)