diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 3f8d2399da1..4de692ce3e9 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -709,6 +709,9 @@ class CppCheckHandler(XmlContentHandler): error = self.errors[-1] locations = error['locations'] file = attributes['file'] + # Cppcheck Premium reports license messages with this pseudo file name + if file == 'Cppcheck Premium': + file = '' line = int(attributes['line']) if not locations: error['file'] = file diff --git a/test/tools/htmlreport/test_htmlreport.py b/test/tools/htmlreport/test_htmlreport.py index b8c73072a70..d5ac11aa16b 100755 --- a/test/tools/htmlreport/test_htmlreport.py +++ b/test/tools/htmlreport/test_htmlreport.py @@ -140,6 +140,25 @@ def testEscape(self): output_directory.cleanup() + def testPremiumLicenseMessage(self): + with tempfile.TemporaryDirectory() as tmpdir: + xml_filename = os.path.join(tmpdir, 'premium.xml') + with open(xml_filename, 'w') as f: + f.write('\n' + '\n' + '\n' + '\n' + '\n' + '\n') + output_directory = os.path.join(tmpdir, 'out') + p = subprocess.run([*HTML_REPORT_BIN, '--file=' + xml_filename, '--report-dir=' + output_directory], + capture_output=True, text=True, check=True) + self.assertNotIn('not found', p.stderr) + with open(os.path.join(output_directory, 'index.html')) as index_file: + report = index_file.read() + self.assertIn('license will expire', report) + self.assertNotIn('0.html#line-0', report) + @contextlib.contextmanager def runCheck(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None):