@@ -12,7 +12,7 @@ import parse from 'spdx-expression-parse'
12
12
// accepts a pair of well-formed SPDX expressions. the
13
13
// candidate is tested against the constraint
14
14
export function satisfies ( candidateExpr : string , allowList : string [ ] ) : boolean {
15
- candidateExpr = removeInvalidSPDX ( candidateExpr )
15
+ candidateExpr = cleanInvalidSPDX ( candidateExpr )
16
16
try {
17
17
return spdxSatisfies ( candidateExpr , allowList )
18
18
} catch ( _ ) {
@@ -25,7 +25,7 @@ export function satisfiesAny(
25
25
candidateExpr : string ,
26
26
licenses : string [ ]
27
27
) : boolean {
28
- candidateExpr = removeInvalidSPDX ( candidateExpr )
28
+ candidateExpr = cleanInvalidSPDX ( candidateExpr )
29
29
try {
30
30
return spdxlib . satisfiesAny ( candidateExpr , licenses )
31
31
} catch ( _ ) {
@@ -38,7 +38,7 @@ export function satisfiesAll(
38
38
candidateExpr : string ,
39
39
licenses : string [ ]
40
40
) : boolean {
41
- candidateExpr = removeInvalidSPDX ( candidateExpr )
41
+ candidateExpr = cleanInvalidSPDX ( candidateExpr )
42
42
try {
43
43
return spdxlib . satisfiesAll ( candidateExpr , licenses )
44
44
} catch ( _ ) {
@@ -48,7 +48,7 @@ export function satisfiesAll(
48
48
49
49
// accepts any SPDX expression
50
50
export function isValid ( spdxExpr : string ) : boolean {
51
- spdxExpr = removeInvalidSPDX ( spdxExpr )
51
+ spdxExpr = cleanInvalidSPDX ( spdxExpr )
52
52
try {
53
53
parse ( spdxExpr )
54
54
return true
@@ -57,10 +57,10 @@ export function isValid(spdxExpr: string): boolean {
57
57
}
58
58
}
59
59
60
- const replaceOtherRegex = / (?< ! [ \w - ] ) O T H E R (? ! [ \w - ] ) /
60
+ const replaceOtherRegex = / (?< ! [ \w - ] ) O T H E R (? ! [ \w - ] ) / g
61
61
62
62
// adjusts license expressions to not include the invalid `OTHER`
63
63
// which ClearlyDefined adds to license strings
64
- export function removeInvalidSPDX ( spdxExpr : string ) : string {
64
+ export function cleanInvalidSPDX ( spdxExpr : string ) : string {
65
65
return spdxExpr . replace ( replaceOtherRegex , 'LicenseRef-clearlydefined-OTHER' )
66
66
}
0 commit comments