Skip to content

Commit 9872108

Browse files
committed
Fix bug in any and all conditions
Due to wrong handling of any and all functions license matches are categorized as having full relevance or copyrights, even if they do not. This leads to a regression in false positive detection. Correct the any and all conditions to correctly detect copyrights and relevance. Signed-off-by: alexzurbonsen <alexander.zur.bonsen@tngtech.com>
1 parent e830934 commit 9872108

File tree

2 files changed

+55
-141
lines changed

2 files changed

+55
-141
lines changed

src/licensedcode/detection.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,26 +1166,22 @@ def is_false_positive(license_matches, package_license=False):
11661166
# FIXME: actually run copyright detection here?
11671167
copyright_words = ["copyright", "(c)"]
11681168
has_copyrights = all(
1169-
True
1170-
for license_match in license_matches
1171-
if any(
1172-
True
1169+
any(
1170+
word in license_match.matched_text().lower()
11731171
for word in copyright_words
1174-
if word in license_match.matched_text().lower()
1175-
)
1172+
)
1173+
for license_match in license_matches
11761174
)
11771175
has_full_relevance = all(
1178-
True
1176+
license_match.rule.relevance == 100
11791177
for license_match in license_matches
1180-
if license_match.rule.relevance == 100
11811178
)
11821179
if has_copyrights or has_full_relevance:
11831180
return False
11841181

11851182
has_low_relevance = all(
1186-
True
1183+
license_match.rule.relevance < 60
11871184
for license_match in license_matches
1188-
if license_match.rule.relevance < 60
11891185
)
11901186

11911187
start_line_region = min(

tests/licensedcode/data/plugin_license/scan/ffmpeg-license.expected.json

Lines changed: 49 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -82,47 +82,6 @@
8282
}
8383
]
8484
},
85-
{
86-
"identifier": "gpl_2_0_and_lgpl_2_0_plus-e597690d-3d55-0948-8697-914f460389e8",
87-
"license_expression": "gpl-2.0 AND lgpl-2.0-plus",
88-
"license_expression_spdx": "GPL-2.0-only AND LGPL-2.0-or-later",
89-
"detection_count": 1,
90-
"detection_log": [],
91-
"reference_matches": [
92-
{
93-
"license_expression": "gpl-2.0",
94-
"license_expression_spdx": "GPL-2.0-only",
95-
"from_file": "ffmpeg-LICENSE.md",
96-
"start_line": 100,
97-
"end_line": 100,
98-
"matcher": "2-aho",
99-
"score": 100.0,
100-
"matched_length": 1,
101-
"match_coverage": 100.0,
102-
"rule_relevance": 100,
103-
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
104-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
105-
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
106-
"matched_text_diagnostics": "GPLv2"
107-
},
108-
{
109-
"license_expression": "lgpl-2.0-plus",
110-
"license_expression_spdx": "LGPL-2.0-or-later",
111-
"from_file": "ffmpeg-LICENSE.md",
112-
"start_line": 101,
113-
"end_line": 101,
114-
"matcher": "2-aho",
115-
"score": 60.0,
116-
"matched_length": 1,
117-
"match_coverage": 100.0,
118-
"rule_relevance": 60,
119-
"rule_identifier": "lgpl_bare_single_word.RULE",
120-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
121-
"matched_text": "licenses are compatible with the LGPL.",
122-
"matched_text_diagnostics": "LGPL."
123-
}
124-
]
125-
},
12685
{
12786
"identifier": "ijg_and_mit-e50613dc-8a09-65cc-c498-5d9527795382",
12887
"license_expression": "ijg AND mit",
@@ -182,31 +141,6 @@
182141
}
183142
]
184143
},
185-
{
186-
"identifier": "lgpl_2_0_plus-e66c5b24-33ce-ea1b-0e3b-28952361ec32",
187-
"license_expression": "lgpl-2.0-plus",
188-
"license_expression_spdx": "LGPL-2.0-or-later",
189-
"detection_count": 1,
190-
"detection_log": [],
191-
"reference_matches": [
192-
{
193-
"license_expression": "lgpl-2.0-plus",
194-
"license_expression_spdx": "LGPL-2.0-or-later",
195-
"from_file": "ffmpeg-LICENSE.md",
196-
"start_line": 104,
197-
"end_line": 104,
198-
"matcher": "2-aho",
199-
"score": 60.0,
200-
"matched_length": 1,
201-
"match_coverage": 100.0,
202-
"rule_relevance": 60,
203-
"rule_identifier": "lgpl_bare_single_word.RULE",
204-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
205-
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
206-
"matched_text_diagnostics": "LGPL"
207-
}
208-
]
209-
},
210144
{
211145
"identifier": "lgpl_2_1_plus_and_other_permissive_and_gpl_2_0_plus-666058ef-8c38-3b17-d8e7-448b304de833",
212146
"license_expression": "lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus",
@@ -294,8 +228,8 @@
294228
{
295229
"path": "ffmpeg-LICENSE.md",
296230
"type": "file",
297-
"detected_license_expression": "(lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus) AND (lgpl-3.0 AND lgpl-3.0-plus AND (lgpl-3.0 AND gpl-3.0)) AND (ijg AND mit) AND gpl-1.0-plus AND (gpl-2.0 AND apache-2.0 AND lgpl-3.0-plus) AND (gpl-2.0 AND lgpl-2.0-plus) AND lgpl-2.0-plus",
298-
"detected_license_expression_spdx": "(LGPL-2.1-or-later AND LicenseRef-scancode-other-permissive AND GPL-2.0-or-later) AND (LGPL-3.0-only AND LGPL-3.0-or-later AND (LGPL-3.0-only AND GPL-3.0-only)) AND (IJG AND MIT) AND GPL-1.0-or-later AND (GPL-2.0-only AND Apache-2.0 AND LGPL-3.0-or-later) AND (GPL-2.0-only AND LGPL-2.0-or-later) AND LGPL-2.0-or-later",
231+
"detected_license_expression": "(lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus) AND (lgpl-3.0 AND lgpl-3.0-plus AND (lgpl-3.0 AND gpl-3.0)) AND (ijg AND mit) AND gpl-1.0-plus AND (gpl-2.0 AND apache-2.0 AND lgpl-3.0-plus)",
232+
"detected_license_expression_spdx": "(LGPL-2.1-or-later AND LicenseRef-scancode-other-permissive AND GPL-2.0-or-later) AND (LGPL-3.0-only AND LGPL-3.0-or-later AND (LGPL-3.0-only AND GPL-3.0-only)) AND (IJG AND MIT) AND GPL-1.0-or-later AND (GPL-2.0-only AND Apache-2.0 AND LGPL-3.0-or-later)",
299233
"license_detections": [
300234
{
301235
"license_expression": "lgpl-2.1-plus AND other-permissive AND gpl-2.0-plus",
@@ -514,73 +448,41 @@
514448
],
515449
"detection_log": [],
516450
"identifier": "gpl_2_0_and_apache_2_0_and_lgpl_3_0_plus-c2393e5a-e531-304f-58a9-a6431d46d214"
517-
},
451+
}
452+
],
453+
"license_clues": [
518454
{
519-
"license_expression": "gpl-2.0 AND lgpl-2.0-plus",
520-
"license_expression_spdx": "GPL-2.0-only AND LGPL-2.0-or-later",
521-
"matches": [
522-
{
523-
"license_expression": "gpl-2.0",
524-
"license_expression_spdx": "GPL-2.0-only",
525-
"from_file": "ffmpeg-LICENSE.md",
526-
"start_line": 100,
527-
"end_line": 100,
528-
"matcher": "2-aho",
529-
"score": 100.0,
530-
"matched_length": 1,
531-
"match_coverage": 100.0,
532-
"rule_relevance": 100,
533-
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
534-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
535-
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
536-
"matched_text_diagnostics": "GPLv2"
537-
},
538-
{
539-
"license_expression": "lgpl-2.0-plus",
540-
"license_expression_spdx": "LGPL-2.0-or-later",
541-
"from_file": "ffmpeg-LICENSE.md",
542-
"start_line": 101,
543-
"end_line": 101,
544-
"matcher": "2-aho",
545-
"score": 60.0,
546-
"matched_length": 1,
547-
"match_coverage": 100.0,
548-
"rule_relevance": 60,
549-
"rule_identifier": "lgpl_bare_single_word.RULE",
550-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
551-
"matched_text": "licenses are compatible with the LGPL.",
552-
"matched_text_diagnostics": "LGPL."
553-
}
554-
],
555-
"detection_log": [],
556-
"identifier": "gpl_2_0_and_lgpl_2_0_plus-e597690d-3d55-0948-8697-914f460389e8"
455+
"license_expression": "gpl-2.0",
456+
"license_expression_spdx": "GPL-2.0-only",
457+
"from_file": "ffmpeg-LICENSE.md",
458+
"start_line": 100,
459+
"end_line": 100,
460+
"matcher": "2-aho",
461+
"score": 100.0,
462+
"matched_length": 1,
463+
"match_coverage": 100.0,
464+
"rule_relevance": 100,
465+
"rule_identifier": "gpl-2.0_bare_single_word.RULE",
466+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/gpl-2.0_bare_single_word.RULE",
467+
"matched_text": "are incompatible with the GPLv2 and v3. We do not know for certain if their",
468+
"matched_text_diagnostics": "GPLv2"
557469
},
558470
{
559471
"license_expression": "lgpl-2.0-plus",
560472
"license_expression_spdx": "LGPL-2.0-or-later",
561-
"matches": [
562-
{
563-
"license_expression": "lgpl-2.0-plus",
564-
"license_expression_spdx": "LGPL-2.0-or-later",
565-
"from_file": "ffmpeg-LICENSE.md",
566-
"start_line": 104,
567-
"end_line": 104,
568-
"matcher": "2-aho",
569-
"score": 60.0,
570-
"matched_length": 1,
571-
"match_coverage": 100.0,
572-
"rule_relevance": 60,
573-
"rule_identifier": "lgpl_bare_single_word.RULE",
574-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
575-
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
576-
"matched_text_diagnostics": "LGPL"
577-
}
578-
],
579-
"detection_log": [],
580-
"identifier": "lgpl_2_0_plus-e66c5b24-33ce-ea1b-0e3b-28952361ec32"
581-
}
582-
],
583-
"license_clues": [
473+
"from_file": "ffmpeg-LICENSE.md",
474+
"start_line": 101,
475+
"end_line": 101,
476+
"matcher": "2-aho",
477+
"score": 60.0,
478+
"matched_length": 1,
479+
"match_coverage": 100.0,
480+
"rule_relevance": 60,
481+
"rule_identifier": "lgpl_bare_single_word.RULE",
482+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
483+
"matched_text": "licenses are compatible with the LGPL.",
484+
"matched_text_diagnostics": "LGPL."
485+
},
584486
{
585487
"license_expression": "proprietary-license",
586488
"license_expression_spdx": "LicenseRef-scancode-proprietary-license",
@@ -596,10 +498,26 @@
596498
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/proprietary-license_490.RULE",
597499
"matched_text": "If you wish to enable these libraries, pass --enable-nonfree to configure.",
598500
"matched_text_diagnostics": "enable-nonfree"
501+
},
502+
{
503+
"license_expression": "lgpl-2.0-plus",
504+
"license_expression_spdx": "LGPL-2.0-or-later",
505+
"from_file": "ffmpeg-LICENSE.md",
506+
"start_line": 104,
507+
"end_line": 104,
508+
"matcher": "2-aho",
509+
"score": 60.0,
510+
"matched_length": 1,
511+
"match_coverage": 100.0,
512+
"rule_relevance": 60,
513+
"rule_identifier": "lgpl_bare_single_word.RULE",
514+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/lgpl_bare_single_word.RULE",
515+
"matched_text": "be under a complex license mix that is more restrictive than the LGPL and that",
516+
"matched_text_diagnostics": "LGPL"
599517
}
600518
],
601519
"percentage_of_license_text": 34.78,
602520
"scan_errors": []
603521
}
604522
]
605-
}
523+
}

0 commit comments

Comments
 (0)