Skip to content

Commit 0c0b87b

Browse files
authored
Merge pull request #3006 from opossum-tool/fix/spdx-validation
fix: remove licenseRef autocomplete and show the same license in the autocomplete as well
2 parents f66331a + 6b5bcc0 commit 0c0b87b

File tree

3 files changed

+15
-51
lines changed

3 files changed

+15
-51
lines changed

src/Frontend/Components/AttributionForm/LicenseSubPanel/LicenseSubPanelAutocomplete.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ export function LicenseSubPanelAutocomplete({
128128
): Array<LicenseOption> {
129129
const [beforeLast, lastLicense] = splitAtLastExpression(inputValue);
130130
const hasExpressionBeforeLastWord = beforeLast !== '';
131-
return options.filter((option) => {
132-
if (option.shortName === lastLicense.trim()) {
133-
return false;
134-
}
131+
const autocompleteOptions = options.filter((option) => {
135132
// Selecting signals or attributions replaces everything, so you have to filter on the full input and not just the last part.
136133
if (option.replaceEntireSearch) {
137134
return option.shortName
@@ -144,6 +141,13 @@ export function LicenseSubPanelAutocomplete({
144141
}
145142
return false;
146143
});
144+
if (
145+
autocompleteOptions.length === 1 &&
146+
autocompleteOptions[0].shortName === lastLicense.trim()
147+
) {
148+
return [];
149+
}
150+
return autocompleteOptions;
147151
}
148152

149153
const validationResult = validateSpdxExpression({

src/Frontend/util/spdx/__test__/validate-spdx.test.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ describe('validateSpdxExpression', () => {
2525
['parentheses', '(MIT OR Apache-2.0) AND BSD-3-Clause'],
2626
['nested parentheses', '((MIT OR Apache-2.0) AND BSD-3-Clause)'],
2727
['extra whitespace', 'MIT AND Apache-2.0'],
28-
['LicenseRef', 'LicenseRef-MyLicense'],
29-
['DocumentRef', 'DocumentRef-ext:LicenseRef-MyLicense'],
3028
])('returns valid for %s', (_, spdxExpression) => {
3129
expect(validateSpdxExpression({ spdxExpression, knownLicenseIds })).toEqual(
3230
{
@@ -93,33 +91,6 @@ describe('validateSpdxExpression', () => {
9391
'mit AND Apache-2.0',
9492
{ unknownId: 'mit', suggestion: 'MIT', fix: 'MIT AND Apache-2.0' },
9593
],
96-
[
97-
'LicenseRef with incorrect casing',
98-
'licenseref-MyLicense',
99-
{
100-
unknownId: 'licenseref-MyLicense',
101-
suggestion: 'LicenseRef-MyLicense',
102-
fix: 'LicenseRef-MyLicense',
103-
},
104-
],
105-
[
106-
'LicenseRef with space',
107-
'LicenseRef MyLicense',
108-
{
109-
unknownId: 'LicenseRef MyLicense',
110-
suggestion: 'LicenseRef-MyLicense',
111-
fix: 'LicenseRef-MyLicense',
112-
},
113-
],
114-
[
115-
'DocumentRef with incorrect casing',
116-
'documentref-ext',
117-
{
118-
unknownId: 'documentref-ext',
119-
suggestion: 'DocumentRef-ext',
120-
fix: 'DocumentRef-ext',
121-
},
122-
],
12394
])('detects %s', (_, spdxExpression, expectedUnknown) => {
12495
expect(validateSpdxExpression({ spdxExpression, knownLicenseIds })).toEqual(
12596
{

src/Frontend/util/spdx/validate-spdx.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const spdxGrammar = grammar(`
8686
// The conjunctions contain spaces so we don't match MITANDAPACHE
8787
// We need the #'s here so we don't consume the spaces before trying to match them, which would fail
8888
CompoundExpression
89-
= LicenseId #with LicenseId
89+
= LicenseExpression #with LicenseExpression
9090
| LicenseExpression #and LicenseExpression
9191
| LicenseExpression #or LicenseExpression
9292
| "(" LicenseExpression ")"
@@ -171,24 +171,13 @@ function getUnknownLicenseIdsWithSuggestions({
171171
)) {
172172
let suggestion: string | undefined = undefined;
173173

174-
if (id.match(/^LicenseRef/i) || id.match(/^DocumentRef/i)) {
175-
suggestion = id
176-
.replace(/^LicenseRef/i, 'LicenseRef')
177-
.replace(/^DocumentRef/i, 'DocumentRef')
178-
.replaceAll(' ', '-');
179-
180-
if (suggestion === id) {
181-
continue;
182-
}
183-
} else {
184-
try {
185-
const spdxCorrection = spdxCorrect(id);
186-
if (spdxCorrection && knownLicenseIds.has(spdxCorrection)) {
187-
suggestion = spdxCorrection;
188-
}
189-
} catch {
190-
// If spxdCorrect fails, we have no suggestion
174+
try {
175+
const spdxCorrection = spdxCorrect(id);
176+
if (spdxCorrection && knownLicenseIds.has(spdxCorrection)) {
177+
suggestion = spdxCorrection;
191178
}
179+
} catch {
180+
// If spxdCorrect fails, we have no suggestion
192181
}
193182

194183
const fix = suggestion

0 commit comments

Comments
 (0)