From 77d2e8630d0942fe827bc94271c06bed209a1929 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Thu, 2 Feb 2017 05:49:02 +0000 Subject: [PATCH] [opt-viewer] HTML-escape function names git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293869 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/opt-viewer/opt-viewer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/opt-viewer/opt-viewer.py b/utils/opt-viewer/opt-viewer.py index 79a869a72791..02a19b134e53 100755 --- a/utils/opt-viewer/opt-viewer.py +++ b/utils/opt-viewer/opt-viewer.py @@ -30,6 +30,7 @@ from pygments import highlight from pygments.lexers.c_cpp import CppLexer from pygments.formatters import HtmlFormatter +import cgi p = subprocess.Popen(['c++filt', '-n'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) p_lock = Lock() @@ -103,7 +104,7 @@ def getArgString(self, mapping): (key, value) = mapping.items()[0] if key == 'Caller' or key == 'Callee': - value = demangle(value) + value = cgi.escape(demangle(value)) if dl and key != 'Caller': return "{}".format( @@ -207,6 +208,7 @@ def render_inline_remarks(self, r, line): # replace everything else with spaces. indent = line[:r.Column - 1] indent = re.sub('\S', ' ', indent) + print(''' @@ -254,11 +256,12 @@ def __init__(self, output_dir): self.stream = open(os.path.join(output_dir, 'index.html'), 'w') def render_entry(self, r, odd): + escaped_name = cgi.escape(r.DemangledFunctionName) print(''' {r.DebugLocString} {r.RelativeHotness} -{r.DemangledFunctionName} +{escaped_name} {r.Pass} '''.format(**locals()), file=self.stream)