From ef91552cfb4b45f75b415dd43fb6a21795c8dbee Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sun, 29 Apr 2018 12:10:39 -0700 Subject: [PATCH] bpo-33256: Replace angle brackets around python object repr to display it in html (GH-6442) (cherry picked from commit 7d68bfa82654ba01d860b8a772ff63bf0bd183ee) Co-authored-by: sblondon --- Lib/cgitb.py | 4 ++-- Lib/test/test_cgitb.py | 1 + Misc/ACKS | 1 + .../next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst diff --git a/Lib/cgitb.py b/Lib/cgitb.py index b29110018cd..0f5f32c0fad 100644 --- a/Lib/cgitb.py +++ b/Lib/cgitb.py @@ -124,7 +124,7 @@ function calls leading up to the error, in the order they occurred.

''' args, varargs, varkw, locals = inspect.getargvalues(frame) call = '' if func != '?': - call = 'in ' + strong(func) + \ + call = 'in ' + strong(pydoc.html.escape(func)) + \ inspect.formatargvalues(args, varargs, varkw, locals, formatvalue=lambda value: '=' + pydoc.html.repr(value)) @@ -282,7 +282,7 @@ class Hook: if self.display: if plain: - doc = doc.replace('&', '&').replace('<', '<') + doc = pydoc.html.escape(doc) self.file.write('
' + doc + '
\n') else: self.file.write(doc + '\n') diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py index a87a4224f94..e299ec3ec6c 100644 --- a/Lib/test/test_cgitb.py +++ b/Lib/test/test_cgitb.py @@ -45,6 +45,7 @@ class TestCgitb(unittest.TestCase): out = out.decode(sys.getfilesystemencoding()) self.assertIn("ValueError", out) self.assertIn("Hello World", out) + self.assertIn("<module>", out) # By default we emit HTML markup. self.assertIn('

', out) self.assertIn('

', out) diff --git a/Misc/ACKS b/Misc/ACKS index 8e250f7bb00..cda62f57909 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -154,6 +154,7 @@ Mike Bland Martin Bless Pablo Bleyer Erik van Blokland +Stéphane Blondon Eric Blossom Sergey Bobrov Finn Bock diff --git a/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst new file mode 100644 index 00000000000..a0605c04b4d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-04-10-20-57-14.bpo-33256.ndHkqu.rst @@ -0,0 +1 @@ +Fix display of ```` call in the html produced by ``cgitb.html()``. Patch by Stéphane Blondon.