Conversation
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The core assumption here conflicts with SPDX's case-sensitivity rules. For user-defined identifiers, the variable part after LicenseRef- is case-insensitive, so LicenseRef-Name and LicenseRef-name refer to the same license rather than two distinct licenses. Preserving each occurrence's casing as a distinct identifier can therefore change the meaning of an expression. Could case variants canonicalize consistently to one identifier instead, with a regression covering mixed-case occurrences?
This branch has not been deployed
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.
When a license expression contains two LicenseRef- identifiers that differ only in case, e.g. 'licenseref-MIT AND LicenseRef-mit', canonicalize_license_expression() rewrote every occurrence to the spelling of the last one seen, returning 'LicenseRef-mit AND LicenseRef-mit'. This happens because the module lowercases the expression for SPDX lookup and then rebuilds each LicenseRef token from a dict keyed by the lowercased token, so one casing silently overwrites the other. After the fix, each occurrence keeps its own spelling and 'licenseref-MIT AND LicenseRef-mit' canonicalizes to 'LicenseRef-MIT AND LicenseRef-mit'.
SPDX LicenseRef- identifiers are case-sensitive: LicenseRef-mit and LicenseRef-MIT name two different licenses. Tests in tests/test_metadata.py already document that a single ref's own spelling is preserved, and the lowercased dict broke that contract for expressions mixing casings of the same base identifier. The fix records the original spelling of each token occurrence (keyed by token index, with a strict zip tie to the lowercased tokens) and looks it up by index while emitting normalized tokens, leaving all other behavior unchanged.
Validation:
AI assistance: implementation and independent review used Hermes with GLM 5.3. Test evidence was reproduced in clean checkouts. This does not represent a human review.