Skip to content

Commit 77a6646

Browse files
committed
Fix bug#1758 in filter-clues plugin
fixed bug by using hasattr check on the resource object and returning empty ignorables if not detections.licenses Signed-off-by: Tushar912 <[email protected]>
1 parent b14ca7b commit 77a6646

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/cluecode/plugin_filter_clues.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ def filter_ignorable_resource_clues(resource, rules_by_id):
102102
detections = Detections.from_resource(resource)
103103
filtered = filter_ignorable_clues(detections, rules_by_id)
104104
if filtered:
105-
resource.emails = filtered.emails
106-
resource.urls = filtered.urls
107-
resource.authors = filtered.authors
108-
resource.holders = filtered.holders
109-
resource.copyrights = filtered.copyrights
105+
if hasattr(resource, 'emails'):
106+
resource.emails = filtered.emails
107+
if hasattr(resource, 'urls'):
108+
resource.urls = filtered.urls
109+
if hasattr(resource, 'authors'):
110+
resource.authors = filtered.authors
111+
if hasattr(resource, 'holders'):
112+
resource.holders = filtered.holders
113+
if hasattr(resource, 'copyrights'):
114+
resource.copyrights = filtered.copyrights
110115
return resource
111116

112117

@@ -220,11 +225,8 @@ def filter_ignorable_clues(detections, rules_by_id):
220225

221226
no_detected_ignorables = not detections.copyrights and not detections.authors
222227

223-
if detections.licenses:
224-
ignorables = collect_ignorables(detections.licenses, rules_by_id)
225-
else:
226-
ignorables = None
227-
228+
ignorables = collect_ignorables(detections.licenses, rules_by_id)
229+
228230
no_ignorables = not detections.licenses or is_empty(ignorables)
229231

230232
if TRACE:
@@ -323,6 +325,14 @@ def collect_ignorables(license_matches, rules_by_id):
323325
holders = set()
324326
copyrights = set()
325327

328+
if not license_matches:
329+
return Ignorables(
330+
copyrights=frozenset(copyrights),
331+
holders=frozenset(holders),
332+
authors=frozenset(authors),
333+
urls=frozenset(urls),
334+
emails=frozenset(emails),
335+
)
326336
# build tuple of (set of lines number, set of ignorbale values)
327337
for lic in license_matches:
328338

tests/scancode/test_cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def test_verbose_option_with_copyrights(monkeypatch):
109109
assert len(open(result_file).read()) > 10
110110

111111

112-
@pytest.mark.xfail(reason='Bug is not fixed yet')
113112
def test_scanned_resource_no_attribute_emails():
114113
test_dir = test_env.get_test_loc('attribute_error_data/apache-1.1.txt')
115114
result_file = test_env.get_temp_file('bb.json')

0 commit comments

Comments
 (0)