fix: resolve SPDX expressions that use the WITH operator - #555
Open
Eljees wants to merge 1 commit into
Open
Conversation
The SPDX parser returns "<license> WITH <exception>" as a single atom, but the SPDX license list is indexed by license ID alone, so looking the atom up always failed. Every affected component logged "unable to get license by ID" and fell back to an unresolved license, which is what users see as Unknown. When the lookup fails and the atom is a WITH expression, retry with the license the exception applies to. The full expression stays on the resulting License, so policy matching -- which goes through License.String() and therefore the SPDX expression -- is unchanged; what changes is that the license is now resolved and carries its name, reference and OSI status instead of nothing. Signed-off-by: Eljees <3.14hell@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #500
Problem
spdxexp.ExtractLicenseshands back aWITHexpression as a single atom, and the SPDX license list is indexed by license ID alone, so the lookup inhandleSPDXLicensecan never succeed for it. Probed against the parser and index this repo already uses:So every component carrying an exception logs
unable to get license by IDand falls through toaddNonSPDXLicense, which is theUnknownin the report from the issue.Change
When the lookup fails and the atom is a
WITHexpression, retry with the license the exception applies to.Deliberately narrow:
License.SPDXExpression. Policy matching goes throughLicense.String(), which returns that expression, so no rule that matches today starts or stops matching.+on the license part is trimmed, matching what the surrounding code already does for plain atoms.What changes is that the license resolves: name, reference, details URL and OSI status now come from the base license instead of being empty. The exception itself is not recorded separately —
Licensehas no field for it, and adding one would change the JSON output — but it remains visible in the expression.Tests
TestConvertSyftLicenses_SPDXExpressionWithExceptioncoversApache-2.0 WITH LLVM-exceptionandGPL-2.0-only WITH Classpath-exception-2.0.With
grant/license.goreverted to its state onmain:With the change: