Skip to content

Commit

Permalink
fix(report): Parse data from sarif as URI, instead of treating it as …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
o-andrieiev committed Oct 28, 2024
1 parent c065c67 commit e50656c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
42 changes: 42 additions & 0 deletions tests/test_code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,46 @@ def finalize(self) -> str:
}
"""

sarif_report_uri = """
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "Checkstyle",
"semanticVersion": "8.43",
"version": "8.43"
}
},
"results": [
{
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///my_path/my_file"
},
"region": {
"startColumn": 1,
"startLine": 1
}
}
}
],
"message": {
"text": "Error!"
},
"ruleId": "testRule"
}
]
}
]
}
"""

config_uncrustify = """
code_width = 120
input_tab_size = 2
Expand All @@ -189,6 +229,7 @@ def finalize(self) -> str:
[[sarif_report_minimal], True],
[[sarif_report], False],
[[sarif_report_split_uri], False],
[[sarif_report_uri], False],
[[json_report_minimal, sarif_report_minimal], True],
[[json_report, sarif_report], False],
[[json_report_minimal, sarif_report], False],
Expand All @@ -199,6 +240,7 @@ def finalize(self) -> str:
'sarif_no_issues',
'sarif_issues_found',
'sarif_split_uri_issues_found',
'sarif_uri',
'both_tested_no_issues',
'both_tested_issues_in_both',
'both_tested_issues_in_sarif',
Expand Down
12 changes: 6 additions & 6 deletions universum/modules/code_report_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def _process_one_sarif_issue(self, issue, root_uri_base_paths, who) -> None:
if location_data.get('address'):
continue # binary artifact can't be processed
raise ValueError("Unexpected lack of artifactLocation tag")
uri = artifact_data.get('uri')
if not uri:
raise ValueError("Unexpected lack of uri tag")
path = urllib.parse.unquote(urllib.parse.urlparse(uri).path)
if artifact_data.get('uriBaseId'):
uri = artifact_data.get('uri')
if not uri:
raise ValueError("Unexpected lack of uri tag")
# means path is relative, need to make absolute
uri_base_id = artifact_data.get('uriBaseId', '')
root_base_path = root_uri_base_paths.get(uri_base_id, '')
if uri_base_id and not root_base_path:
raise ValueError(f"Unexpected lack of 'originalUriBaseIds' value for {uri_base_id}")
path = str(Path(root_base_path, urllib.parse.unquote(uri)))
else:
path = urllib.parse.unquote(artifact_data.get('uri', ''))
path = str(Path(root_base_path) / path)
region_data = location_data.get('region')
if not region_data:
continue # TODO: cover this case as comment to the file as a whole
Expand Down

0 comments on commit e50656c

Please sign in to comment.