Fix 'AND' detection failures and filter redundant 'OR' matches #4691
+29
−0
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 #4690
The Issue
ScanCode was failing to correctly handle composite license expressions in two specific edge cases:
The "AND" Failure (Dropping Data):
Apache-2.0 AND MITApache-2.0Apache-2.0 AND MITThe "OR" Failure (Redundancy):
Apache-2.0 OR MITApache-2.0 OR MIT+Apache-2.0Apache-2.0 OR MITSummary of Changes
This PR fixes both issues by tightening the data rules and adding a clean-up filter:
apache-2.0_and_mit_37.RULEto explicitly catch "Apache-2.0 AND MIT" as a single unit. This prevents the tokenizer from treating the short "MIT" string as discardable noise.detection.pyto filter out subset matches. If a detected license (e.g.,Apache-2.0) is fully contained within a larger detected expression (e.g.,Apache-2.0 OR MIT), the redundant subset is now discarded.Verification
Verified locally with a new test case (
tests/licensedcode/test_issue_4690.py) covering both scenarios. The output now correctly reports single, accurate composite license expressions for both cases without dropping data or adding duplicates.Tasks