From 68f273ee5446cdc7e135a57de3da24e8bdf814c2 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 27 Nov 2022 10:28:01 +0100 Subject: [PATCH] Fix #17 [main] - set language to `unknown` when langdetect cannot detect the language for some reasons like empty commit message or unknown language. Notes: langdetect exception handler seems to be crap and do not use a Base Exception handler. That's why the catch-all ;-) --- git_vuln_finder/vulnerability.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/git_vuln_finder/vulnerability.py b/git_vuln_finder/vulnerability.py index 606ad16..bf22dda 100644 --- a/git_vuln_finder/vulnerability.py +++ b/git_vuln_finder/vulnerability.py @@ -82,9 +82,11 @@ def summary( else: potential_vulnerabilities[rcommit.hexsha] = {} potential_vulnerabilities[rcommit.hexsha]["message"] = rcommit.message - potential_vulnerabilities[rcommit.hexsha]["language"] = langdetect( - rcommit.message - ) + try: + lang = langdetect(rcommit.message) + except: + lang = "unknown" + potential_vulnerabilities[rcommit.hexsha]["language"] = lang potential_vulnerabilities[rcommit.hexsha]["commit-id"] = rcommit.hexsha potential_vulnerabilities[rcommit.hexsha]["summary"] = rcommit.summary potential_vulnerabilities[rcommit.hexsha]["stats"] = rcommit.stats.total @@ -128,7 +130,7 @@ def summary_event( commit_state="under-review" ): potential_vulnerabilities = {} - + cve, cve_found = extract_cve(commit["message"]) potential_vulnerabilities[commit["sha"]] = {}