Skip to content

Commit 7d027f3

Browse files
Merge pull request #2353 from tushar912/issue-1758
Fix bug in filter-clues plugin
2 parents f3ef5b4 + 77a6646 commit 7d027f3

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
@@ -81,11 +81,16 @@ def filter_ignorable_resource_clues(resource, rules_by_id):
8181
detections = Detections.from_resource(resource)
8282
filtered = filter_ignorable_clues(detections, rules_by_id)
8383
if filtered:
84-
resource.emails = filtered.emails
85-
resource.urls = filtered.urls
86-
resource.authors = filtered.authors
87-
resource.holders = filtered.holders
88-
resource.copyrights = filtered.copyrights
84+
if hasattr(resource, 'emails'):
85+
resource.emails = filtered.emails
86+
if hasattr(resource, 'urls'):
87+
resource.urls = filtered.urls
88+
if hasattr(resource, 'authors'):
89+
resource.authors = filtered.authors
90+
if hasattr(resource, 'holders'):
91+
resource.holders = filtered.holders
92+
if hasattr(resource, 'copyrights'):
93+
resource.copyrights = filtered.copyrights
8994
return resource
9095

9196

@@ -199,11 +204,8 @@ def filter_ignorable_clues(detections, rules_by_id):
199204

200205
no_detected_ignorables = not detections.copyrights and not detections.authors
201206

202-
if detections.licenses:
203-
ignorables = collect_ignorables(detections.licenses, rules_by_id)
204-
else:
205-
ignorables = None
206-
207+
ignorables = collect_ignorables(detections.licenses, rules_by_id)
208+
207209
no_ignorables = not detections.licenses or is_empty(ignorables)
208210

209211
if TRACE:
@@ -302,6 +304,14 @@ def collect_ignorables(license_matches, rules_by_id):
302304
holders = set()
303305
copyrights = set()
304306

307+
if not license_matches:
308+
return Ignorables(
309+
copyrights=frozenset(copyrights),
310+
holders=frozenset(holders),
311+
authors=frozenset(authors),
312+
urls=frozenset(urls),
313+
emails=frozenset(emails),
314+
)
305315
# build tuple of (set of lines number, set of ignorbale values)
306316
for lic in license_matches:
307317

tests/scancode/test_cli.py

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

7878

79-
@pytest.mark.xfail(reason='Bug is not fixed yet')
8079
def test_scanned_resource_no_attribute_emails():
8180
test_dir = test_env.get_test_loc('attribute_error_data/apache-1.1.txt')
8281
result_file = test_env.get_temp_file('bb.json')

0 commit comments

Comments
 (0)