Skip to content

Commit ef91552

Browse files
bpo-33256: Replace angle brackets around python object repr to display it in html (GH-6442)
(cherry picked from commit 7d68bfa) Co-authored-by: sblondon <sblondon@users.noreply.github.com>
1 parent a26a297 commit ef91552

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

Lib/cgitb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def html(einfo, context=5):
124124
args, varargs, varkw, locals = inspect.getargvalues(frame)
125125
call = ''
126126
if func != '?':
127-
call = 'in ' + strong(func) + \
127+
call = 'in ' + strong(pydoc.html.escape(func)) + \
128128
inspect.formatargvalues(args, varargs, varkw, locals,
129129
formatvalue=lambda value: '=' + pydoc.html.repr(value))
130130

@@ -282,7 +282,7 @@ def handle(self, info=None):
282282

283283
if self.display:
284284
if plain:
285-
doc = doc.replace('&', '&amp;').replace('<', '&lt;')
285+
doc = pydoc.html.escape(doc)
286286
self.file.write('<pre>' + doc + '</pre>\n')
287287
else:
288288
self.file.write(doc + '\n')

Lib/test/test_cgitb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def test_syshook_no_logdir_default_format(self):
4545
out = out.decode(sys.getfilesystemencoding())
4646
self.assertIn("ValueError", out)
4747
self.assertIn("Hello World", out)
48+
self.assertIn("<strong>&lt;module&gt;</strong>", out)
4849
# By default we emit HTML markup.
4950
self.assertIn('<p>', out)
5051
self.assertIn('</p>', out)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Mike Bland
154154
Martin Bless
155155
Pablo Bleyer
156156
Erik van Blokland
157+
Stéphane Blondon
157158
Eric Blossom
158159
Sergey Bobrov
159160
Finn Bock
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix display of ``<module>`` call in the html produced by ``cgitb.html()``. Patch by Stéphane Blondon.

0 commit comments

Comments
 (0)