8123: Escape HTML chars in page title.
authorTom Clegg <tom@curoverse.com>
Mon, 25 Jan 2016 21:05:56 +0000 (16:05 -0500)
committerTom Clegg <tom@curoverse.com>
Mon, 25 Jan 2016 21:05:56 +0000 (16:05 -0500)
tools/crunchstat-summary/crunchstat_summary/chartjs.py
tools/crunchstat-summary/tests/test_examples.py

index 590df27fff02224c3fa9e9b7324ffb4ed8186884..fb30041889c726e4cc14d93a5aaeb7b4e1fbbbd9 100644 (file)
@@ -1,5 +1,6 @@
 from __future__ import print_function
 
+import cgi
 import json
 import pkg_resources
 
@@ -19,7 +20,7 @@ class ChartJS(object):
         <script type="text/javascript" src="{}"></script>
         <script type="text/javascript">{}</script>
         </head><body></body></html>
-        '''.format(self.label, self.JSLIB, self.js())
+        '''.format(cgi.escape(self.label), self.JSLIB, self.js())
 
     def js(self):
         return 'var sections = {};\n{}'.format(
index 4fe7b27070747162a2a7778af5aa47d6a7774489..6c1443733c35ec9ea76bd35e49fb3c69d6f83906 100644 (file)
@@ -34,6 +34,20 @@ class SummarizeFile(ReportDiff):
             self.diff_known_report(logfile, cmd)
 
 
+class HTMLFromFile(ReportDiff):
+    def test_example_files(self):
+        # Note we don't test the output content at all yet; we're
+        # mainly just verifying the --format=html option isn't ignored
+        # and the HTML code path doesn't crash.
+        for fnm in glob.glob(os.path.join(TESTS_DIR, '*.txt.gz')):
+            logfile = os.path.join(TESTS_DIR, fnm)
+            args = crunchstat_summary.command.ArgumentParser().parse_args(
+                ['--format=html', '--log-file', logfile])
+            cmd = crunchstat_summary.command.Command(args)
+            cmd.run()
+            self.assertRegexpMatches(cmd.report(), r'(?is)<html>.*</html>\s*$')
+
+
 class SummarizeEdgeCases(unittest.TestCase):
     def test_error_messages(self):
         logfile = open(os.path.join(TESTS_DIR, 'crunchstat_error_messages.txt'))