From be9265c3b90a6da3e23b5867f3df57b95bce62a3 Mon Sep 17 00:00:00 2001 From: Oleksandr Andrieiev <40266373+o-andrieiev@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:54:26 +0200 Subject: [PATCH] fix(report): adjust for relative uri path --- tests/test_code_report.py | 2 +- universum/modules/code_report_collector.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_code_report.py b/tests/test_code_report.py index 34f1a8e0..cc76cb67 100644 --- a/tests/test_code_report.py +++ b/tests/test_code_report.py @@ -161,7 +161,7 @@ def finalize(self) -> str: ], "originalUriBaseIds": { "ROOTPATH": { - "uri": "my_path" + "uri": "file:///my_path" } } } diff --git a/universum/modules/code_report_collector.py b/universum/modules/code_report_collector.py index e2ebd49f..35cefba7 100644 --- a/universum/modules/code_report_collector.py +++ b/universum/modules/code_report_collector.py @@ -68,14 +68,15 @@ def _process_one_sarif_issue(self, issue, root_uri_base_paths, who) -> None: 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'): # 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: + base_uri = root_uri_base_paths.get(uri_base_id, '') + if uri_base_id and not base_uri: raise ValueError(f"Unexpected lack of 'originalUriBaseIds' value for {uri_base_id}") - path = str(Path(root_base_path) / path) + else: + base_uri = '' + path = str(Path(urllib.parse.urlparse(urllib.parse.urljoin(base_uri, uri)).path)) region_data = location_data.get('region') if not region_data: continue # TODO: cover this case as comment to the file as a whole