From 4f927ea6c7812164ca846e63d5c650d228357c78 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 1 Nov 2019 15:06:44 +0100 Subject: [PATCH] htmlreport: Add HTML validation and fix syntax errors (#2317) Add HTML validation with HTML Tidy for the resulting files index.html and stats.html. Fix syntax errors found by the validator. Fix that the links in the footer are not clickable by removing the "height: 75%;" style for the classes "menu" and "menu_index". Add some line breaks to the HTML output for better readability and for easier debugging. --- .travis.yml | 2 +- htmlreport/check.sh | 33 +++++++++++++++++++++++++++++++++ htmlreport/cppcheck-htmlreport | 33 +++++++++++++++++---------------- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 496ecd20b..0cf61d75e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ env: before_install: # install needed deps - travis_retry sudo apt-get update -qq - - travis_retry sudo apt-get install -qq python3-pip qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev libcurl3 libcairo2-dev libsigc++-2.0-dev + - travis_retry sudo apt-get install -qq python3-pip qt5-default qt5-qmake qtbase5-dev qtcreator libxml2-utils libpcre3 gdb unzip wx-common xmlstarlet python3-dev liblua5.3-dev libcurl3 libcairo2-dev libsigc++-2.0-dev tidy # Python 2 modules - travis_retry python2 -m pip install --user pytest==4.6.4 - travis_retry python2 -m pip install --user pylint diff --git a/htmlreport/check.sh b/htmlreport/check.sh index 828999fff..a0cca748b 100755 --- a/htmlreport/check.sh +++ b/htmlreport/check.sh @@ -1,24 +1,54 @@ #!/bin/bash -ex +# Command for checking HTML syntax with HTML Tidy, see http://www.html-tidy.org/ +# newer tidy (5.6.0) command, if using this it is not necessary to ignore warnings: +#tidy_cmd='tidy -o /dev/null -eq --drop-empty-elements no' +# older tidy from 2009 (Ubuntu 16.04 Xenial comes with this old version): +tidy_cmd='tidy -o /dev/null -eq' + +function validate_html { + set +e + ${tidy_cmd} $1 + tidy_status=$? + set -e + if [ $tidy_status -eq 2 ]; then + echo "HTML does not validate!" + exit 1 + fi +} ./cppcheck-htmlreport --file ../gui/test/data/xmlfiles/xmlreport_v2.xml --title "xml2 test" --report-dir . --source-dir ../test/ echo -e "\n" +# Check HTML syntax +validate_html index.html +validate_html stats.html ../cppcheck ../gui/test --enable=all --inconclusive --xml-version=2 2> gui_test.xml xmllint --noout gui_test.xml ./cppcheck-htmlreport --file ./gui_test.xml --title "xml2 + inconclusive test" --report-dir . echo "" +# Check HTML syntax +validate_html index.html +validate_html stats.html + ../cppcheck ../gui/test --enable=all --inconclusive --verbose --xml-version=2 2> gui_test.xml xmllint --noout gui_test.xml ./cppcheck-htmlreport --file ./gui_test.xml --title "xml2 + inconclusive + verbose test" --report-dir . echo -e "\n" +# Check HTML syntax +validate_html index.html +validate_html stats.html ../cppcheck --errorlist --inconclusive --xml-version=2 > errorlist.xml xmllint --noout errorlist.xml ./cppcheck-htmlreport --file ./errorlist.xml --title "errorlist" --report-dir . +# Check HTML syntax +validate_html index.html +validate_html stats.html + ../cppcheck ../samples/memleak/good.c ../samples/resourceLeak/good.c --xml-version=2 --enable=information --suppressions-list=test_suppressions.txt --xml 2> unmatchedSuppr.xml xmllint --noout unmatchedSuppr.xml @@ -27,3 +57,6 @@ grep "unmatchedSuppression<.*>information<.*>Unmatched suppression: variableScop grep ">unmatchedSuppressioninformation<.*>Unmatched suppression: uninitstring<" index.html grep "notexisting" index.html grep ">unmatchedSuppression<.*>information<.*>Unmatched suppression: \*<" index.html +# Check HTML syntax +validate_html index.html +validate_html stats.html diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 3c99bfbc0..b854d3c2e 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -90,7 +90,7 @@ div.verbose div.content { margin-top: 5px; text-align: left; width: 150px; - height: 75%; + /*height: 75%;*/ position: fixed; overflow: auto; z-index: 1; @@ -102,7 +102,7 @@ div.verbose div.content { padding-left: 5px; text-align: left; width: 300px; - height: 75%; + /*height: 75%;*/ position: fixed; overflow: auto; z-index: 1; @@ -259,7 +259,7 @@ HTML_FOOTER = """
Internet: http://cppcheck.net
IRC: irc://irc.freenode.net/cppcheck
-

+

@@ -573,24 +573,23 @@ if __name__ == '__main__': except IndexError: cnt_min = 0 - stat_fmt = " {}{}" + stat_fmt = "\n {}{}" for occurrences in reversed(range(cnt_min, cnt_max + 1)): for _id in [k for k, v in sorted(counter.items()) if v == occurrences]: stat_html.append(stat_fmt.format(_id, _id, dict(counter.most_common())[_id], _id)) output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defects:", "Defect summary;", 1) % (options.title, '', options.title, '', '')) - output_file.write(' ') - output_file.write(' ') - output_file.write('') + output_file.write('\n ') + output_file.write('\n
Show#Defect ID
') + output_file.write('\n ') output_file.write(''.join(stat_html)) - output_file.write(' ') - output_file.write('
Show#Defect ID
' + str(stats_count) + 'total
') - output_file.write(' Statistics

') + output_file.write('\n ' + str(stats_count) + 'total') + output_file.write('\n ') + output_file.write('\n

Statistics

') output_file.write(HTML_HEAD_END.replace("content", "content_index", 1)) - output_file.write(' \n') - output_file.write( - ' ') + output_file.write('\n
LineIdCWESeverityMessage
') + output_file.write('\n ') for filename, data in sorted(files.items()): if filename in decode_errors: # don't print a link but a note output_file.write("\n " % (filename)) @@ -625,18 +624,18 @@ if __name__ == '__main__': if error['id'] == 'missingInclude': output_file.write( '\n ' % - (error['id'], error['id'], error['severity'], error['msg'])) + (error['id'], error['id'], error['severity'], html_escape(error['msg']))) elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'): output_file.write( '\n ' % (error['id'], error['id'], error['severity'], error_class, - error['msg'])) + html_escape(error['msg']))) else: output_file.write( '\n ' % (error['id'], data['htmlfile'], error['line'], error['line'], error['id'], cwe_url, error['severity'], error_class, - error['msg'])) + html_escape(error['msg']))) output_file.write('\n
LineIdCWESeverityMessage
%s
%s%s%s
%s%s%s
%d%s%s%s%s
') output_file.write(HTML_FOOTER % contentHandler.versionCppcheck) @@ -707,4 +706,6 @@ if __name__ == '__main__': break stats_file.write("

\n") + stats_file.write(HTML_FOOTER % contentHandler.versionCppcheck) + print("\nOpen '" + options.report_dir + "/index.html' to see the results.")