-
Notifications
You must be signed in to change notification settings - Fork 79
Reject deprecated SPDX licenses, but be lenient with committed LICENSE files #754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
69cb351
fix #753 with strict manifest SPDX parsing and lenient detected canon…
thomashoneyman 0187caa
Relax best-effort license parsing
thomashoneyman ec28727
fix SPDX validation boundaries
thomashoneyman 0f2d20a
de-duplicate tests, add 2 missing license mappings
thomashoneyman 38ecab2
Merge branch 'master' into trh/fix-deprecated-licenses
thomashoneyman 887b0d6
move comment
thomashoneyman b833786
Merge branch 'master' into trh/fix-deprecated-licenses
f-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "ambiguous-gfdl-fixture", | ||
| "version": "1.0.0", | ||
| "license": "GFDL-1.3" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "deprecated-agpl-fixture", | ||
| "version": "1.0.0", | ||
| "license": "AGPL-3.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,40 @@ | ||
| import parse from "spdx-expression-parse"; | ||
| import currentIds from "spdx-license-ids/index.json" with { type: "json" }; | ||
| import deprecatedIds from "spdx-license-ids/deprecated.json" with { type: "json" }; | ||
|
|
||
| export const parseSPDXLicenseIdImpl = (onError, onSuccess, identifier) => { | ||
| try { | ||
| parse(identifier); | ||
| return onSuccess(identifier); | ||
| } catch (_) { | ||
| return onError(`Invalid SPDX identifier ${identifier}`); | ||
| export { currentIds, deprecatedIds }; | ||
|
|
||
| const toTree = (onError, node, onLeaf, onAnd, onOr) => { | ||
| if (node.license != null) { | ||
| const plus = node.plus === true; | ||
| const exception = node.exception ?? ""; | ||
| return onLeaf(node.license)(plus)(exception); | ||
| } | ||
| }; | ||
|
|
||
| // Extract all license IDs from a parsed SPDX expression AST. | ||
| // The AST structure from spdx-expression-parse is: | ||
| // - Simple: { license: 'MIT' } | ||
| // - With exception: { license: 'GPL-2.0', exception: 'Classpath-exception-2.0' } | ||
| // - Compound: { left: {...}, conjunction: 'and'|'or', right: {...} } | ||
| const extractLicenseIds = (ast) => { | ||
| const ids = new Set(); | ||
|
|
||
| const walk = (node) => { | ||
| if (!node) return; | ||
| if (node.license) { | ||
| // Normalize to uppercase for case-insensitive comparison | ||
| ids.add(node.license.toUpperCase()); | ||
| if (node.left != null && node.right != null) { | ||
| const left = toTree(onError, node.left, onLeaf, onAnd, onOr); | ||
| const right = toTree(onError, node.right, onLeaf, onAnd, onOr); | ||
|
|
||
| if (node.conjunction === "and") { | ||
| return onAnd(left)(right); | ||
| } | ||
| if (node.left) walk(node.left); | ||
| if (node.right) walk(node.right); | ||
| }; | ||
|
|
||
| walk(ast); | ||
| return Array.from(ids); | ||
| if (node.conjunction === "or") { | ||
| return onOr(left)(right); | ||
| } | ||
|
|
||
| return onError(`Unsupported SPDX conjunction '${String(node.conjunction)}'`); | ||
| } | ||
|
|
||
| return onError("Unsupported SPDX AST node"); | ||
| }; | ||
|
|
||
| export const extractLicenseIdsImpl = (onError, onSuccess, expression) => { | ||
| export const parseLicenseTreeImpl = (onError, onLeaf, onAnd, onOr, expression) => { | ||
| try { | ||
| const ast = parse(expression); | ||
| return onSuccess(extractLicenseIds(ast)); | ||
| } catch (_) { | ||
| return onError(`Invalid SPDX expression: ${expression}`); | ||
| return toTree(onError, ast, onLeaf, onAnd, onOr); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| return onError(`Invalid SPDX expression '${expression}': ${message}`); | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.