From 55733fb987513b59b8b224f4848d2ed6b2ae1ee4 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 19 May 2017 14:47:31 +0100 Subject: [PATCH] Write HTML report as UTF-8 When source code contains non-ASCII characters, `cppcheck-htmlreport` currently dies with an error like: UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 80673: ordinal not in range(128) This is because even though the source code is read as UTF-8, and HTML_HEAD specifies that the file should be read as UTF-8, the output file is opened with the default encoding (ascii). --- htmlreport/cppcheck-htmlreport | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index b3cc50fc8..d43349198 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -497,8 +497,7 @@ if __name__ == '__main__': encoding=options.source_encoding) htmlFormatter.errors = errors - with io.open(os.path.join(options.report_dir, htmlfile), - 'w') as output_file: + with io.open(os.path.join(options.report_dir, htmlfile), 'w', encoding='utf-8') as output_file: output_file.write(HTML_HEAD % (options.title, htmlFormatter.get_style_defs('.highlight'),