Skip to content

Commit

Permalink
Auto merge of #4257 - Turbo87:complex-license-rendering, r=locks
Browse files Browse the repository at this point in the history
utils/license: Add support for parentheses

<img width="317" alt="Bildschirmfoto 2021-12-12 um 18 29 16" src="https://user-images.githubusercontent.com/141300/145722892-c331d94c-d22e-4fcb-a541-7a433724138f.png">

related to #2595
  • Loading branch information
bors committed Dec 12, 2021
2 parents 9c98509 + 0d1a444 commit 193e31b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/utils/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 12 additions & 0 deletions tests/utils/license-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 193e31b

Please sign in to comment.