From 2aa4fdb99a6479868fa5ea6b39d51417ea4381c3 Mon Sep 17 00:00:00 2001 From: bruntib Date: Fri, 3 May 2024 17:07:43 +0200 Subject: [PATCH] [fix] Links in static HTML files should be relative The links in the static HTML files generated by "CodeChecker parse -e html" should be relative, so the output folder of the above command is portable. --- .../report/output/html/html.py | 2 +- .../tests/unit/output/html/plist_to_html_test.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/report-converter/codechecker_report_converter/report/output/html/html.py b/tools/report-converter/codechecker_report_converter/report/output/html/html.py index b049dcaf7b..a7784bf2d8 100644 --- a/tools/report-converter/codechecker_report_converter/report/output/html/html.py +++ b/tools/report-converter/codechecker_report_converter/report/output/html/html.py @@ -309,7 +309,7 @@ def create_index_html(self, output_dir: str): html_report_links.append({'link': html_file, 'report': report}) table_reports = map(lambda data: { - 'link': data['link'], + 'link': os.path.basename(data['link']), 'file-path': data['report']['fileId'], 'report-hash': data['report']['reportHash'], 'checker-name': data['report']['checker']['name'], diff --git a/tools/report-converter/tests/unit/output/html/plist_to_html_test.py b/tools/report-converter/tests/unit/output/html/plist_to_html_test.py index 678556bb46..22d8b44cc1 100644 --- a/tools/report-converter/tests/unit/output/html/plist_to_html_test.py +++ b/tools/report-converter/tests/unit/output/html/plist_to_html_test.py @@ -186,4 +186,10 @@ def test_html_for_inclusion(self): index_html = os.path.join(output_dir, "index.html") with open(index_html, 'r', encoding="utf-8", errors="ignore") as f: - self.assertEqual(len(re.findall('"link": "', f.read())), 3) + content = f.read() + + # There are 3 reports in the test file. + self.assertEqual(len(re.findall('"link": "', content)), 3) + # The links should be relative so the static HTML folder is + # portable. + self.assertNotIn('"link": "/', content)