Fix tests and respond to review feedback
This commit is contained in:
+6
-6
@@ -12,7 +12,7 @@ import parse from 'spdx-expression-parse'
|
||||
// accepts a pair of well-formed SPDX expressions. the
|
||||
// candidate is tested against the constraint
|
||||
export function satisfies(candidateExpr: string, allowList: string[]): boolean {
|
||||
candidateExpr = removeInvalidSPDX(candidateExpr)
|
||||
candidateExpr = cleanInvalidSPDX(candidateExpr)
|
||||
try {
|
||||
return spdxSatisfies(candidateExpr, allowList)
|
||||
} catch (_) {
|
||||
@@ -25,7 +25,7 @@ export function satisfiesAny(
|
||||
candidateExpr: string,
|
||||
licenses: string[]
|
||||
): boolean {
|
||||
candidateExpr = removeInvalidSPDX(candidateExpr)
|
||||
candidateExpr = cleanInvalidSPDX(candidateExpr)
|
||||
try {
|
||||
return spdxlib.satisfiesAny(candidateExpr, licenses)
|
||||
} catch (_) {
|
||||
@@ -38,7 +38,7 @@ export function satisfiesAll(
|
||||
candidateExpr: string,
|
||||
licenses: string[]
|
||||
): boolean {
|
||||
candidateExpr = removeInvalidSPDX(candidateExpr)
|
||||
candidateExpr = cleanInvalidSPDX(candidateExpr)
|
||||
try {
|
||||
return spdxlib.satisfiesAll(candidateExpr, licenses)
|
||||
} catch (_) {
|
||||
@@ -48,7 +48,7 @@ export function satisfiesAll(
|
||||
|
||||
// accepts any SPDX expression
|
||||
export function isValid(spdxExpr: string): boolean {
|
||||
spdxExpr = removeInvalidSPDX(spdxExpr)
|
||||
spdxExpr = cleanInvalidSPDX(spdxExpr)
|
||||
try {
|
||||
parse(spdxExpr)
|
||||
return true
|
||||
@@ -57,10 +57,10 @@ export function isValid(spdxExpr: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
const replaceOtherRegex = /(?<![\w-])OTHER(?![\w-])/
|
||||
const replaceOtherRegex = /(?<![\w-])OTHER(?![\w-])/g
|
||||
|
||||
// adjusts license expressions to not include the invalid `OTHER`
|
||||
// which ClearlyDefined adds to license strings
|
||||
export function removeInvalidSPDX(spdxExpr: string): string {
|
||||
export function cleanInvalidSPDX(spdxExpr: string): string {
|
||||
return spdxExpr.replace(replaceOtherRegex, 'LicenseRef-clearlydefined-OTHER')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user