@@ -92,7 +92,7 @@ def get_scan_types(self):
9292 return ["Mayhem SARIF Report" ]
9393
9494 def get_label_for_scan_types (self , scan_type ):
95- return scan_type
95+ return scan_type
9696
9797 def get_description_for_scan_types (self , scan_type ):
9898 return "Mayhem SARIF reports from code or API runs."
@@ -189,6 +189,7 @@ def get_result_cwes_properties(result):
189189 search_cwe (value , cwes )
190190 return cwes
191191
192+
192193def get_result_cwes_mcode (result ):
193194 """Mayhem SARIF reports include CWE property under taxa.toolComponent.name and number under taxa.id"""
194195 cwes = []
@@ -207,29 +208,28 @@ def get_artifacts(run):
207208 artifacts [tree_artifact .get ("index" , custom_index )] = tree_artifact
208209 return artifacts
209210
211+
210212def clean_mayhem_title_text (text ):
211- """
212- Clean the title text for Mayhem SARIF reports.
213- """
213+ """Clean the title text for Mayhem SARIF reports."""
214214 if not text :
215215 return ""
216-
216+
217217 # Remove links (and add limit to avoid catastrophic backtracking)
218218 link_regex = r"\[[^\]]{1,100}?\]\([^)]{1,200}?\)"
219219 text = re .sub (link_regex , "" , text )
220-
220+
221221 # Remove URL encoded characters
222222 url_encoding_regex = r"&#x\d+;"
223223 text = re .sub (url_encoding_regex , "" , text )
224-
224+
225225 # Remove single or double quotes
226226 quotes_regex = r"[\"']"
227227 text = re .sub (quotes_regex , "" , text )
228228
229229 # Remove TDID
230230 tdid_regex = r"TDID-\d+\s*-\s*|TDID-\d+-"
231231 text = re .sub (tdid_regex , "" , text )
232-
232+
233233 return text .strip ()
234234
235235
@@ -239,19 +239,19 @@ def get_message_from_multiformatMessageString(data, rule, content_type="text"):
239239
240240 See here for the specification: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317468
241241 """
242- if content_type not in [ "text" , "markdown" ] :
243- raise ValueError (f "Unexpected content type: { content_type } " )
242+ if content_type not in { "text" , "markdown" } :
243+ raise ValueError ("Unexpected message content; expected 'text' or 'markdown'. " )
244244 if content_type == "markdown" and "markdown" in data :
245245 # handle markdown content
246246 markdown = data .get ("markdown" )
247247 # strip "headings" or anything that changes text size
248248 heading_regex = r"^#+\s*"
249249 markdown = re .sub (heading_regex , "" , markdown , flags = re .MULTILINE )
250250 # replace non-unicode characters with "?"
251- non_unicode_regex = r' [^\x09\x0A\x0D\x20-\x7E]'
252- markdown = re .sub (non_unicode_regex , '?' , markdown )
251+ non_unicode_regex = r" [^\x09\x0A\x0D\x20-\x7E]"
252+ markdown = re .sub (non_unicode_regex , "?" , markdown )
253253 return markdown .strip ()
254- elif content_type == "text" and "text" in data :
254+ if content_type == "text" and "text" in data :
255255 # handle text content
256256 text = data .get ("text" )
257257 if rule is not None and "id" in data :
@@ -266,6 +266,7 @@ def get_message_from_multiformatMessageString(data, rule, content_type="text"):
266266 else :
267267 return ""
268268
269+
269270def cve_try (val ):
270271 # Match only the first CVE!
271272 cveSearch = re .search (r"(CVE-[0-9]+-[0-9]+)" , val , re .IGNORECASE )
@@ -297,7 +298,7 @@ def get_title(result, rule):
297298 if title is None :
298299 msg = "No information found to create a title"
299300 raise ValueError (msg )
300-
301+
301302 # Clean the title text for Mayhem SARIF reports
302303 title = clean_mayhem_title_text (title )
303304
@@ -374,7 +375,8 @@ def get_codeFlowsDescription(code_flows):
374375
375376 description += f"\t { message } \n "
376377
377- return description
378+ return description
379+
378380
379381def get_description (result , rule , location ):
380382 description = ""
@@ -400,10 +402,7 @@ def get_description(result, rule, location):
400402 fullDescription = get_message_from_multiformatMessageString (
401403 rule ["fullDescription" ], rule ,
402404 )
403- if (
404- fullDescription != message
405- and fullDescription != shortDescription
406- ):
405+ if (fullDescription != message ) and (fullDescription != shortDescription ):
407406 description += f"**{ _ ('Rule full description' )} :** { fullDescription } \n "
408407 if "markdown" in result ["message" ]:
409408 markdown = get_message_from_multiformatMessageString (
@@ -412,7 +411,7 @@ def get_description(result, rule, location):
412411 # Replace "Details" with "Link" in the markdown
413412 markdown = markdown .replace ("Details" , "Link" )
414413 description += f"**{ _ ('Additional Details' )} :**\n { markdown } \n "
415- description += f "_(Unprintable characters are replaced with '?'; please see Mayhem for full reproducer.)_"
414+ description += "_(Unprintable characters are replaced with '?'; please see Mayhem for full reproducer.)_"
416415 if len (result .get ("codeFlows" , [])) > 0 :
417416 description += get_codeFlowsDescription (result ["codeFlows" ])
418417
0 commit comments