summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorPratyush Mittal <pratyushmittal@gmail.com>2021-10-28 23:45:01 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-29 12:09:23 +0200
commitf38458fe56bf8850da72a924bd2e8ff59c6adf06 (patch)
tree5da6146a43001407d96703fbf8ff2b527e3f9e56 /django/test
parent073b7b5915fdfb89a144e81173176ee13ff92a25 (diff)
Fixed #33236 -- Fixed assertHTMLEqual() error messages for escaped HTML.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/html.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/test/html.py b/django/test/html.py
index f1cbadfc54..07e986439b 100644
--- a/django/test/html.py
+++ b/django/test/html.py
@@ -1,5 +1,5 @@
"""Compare two HTML documents."""
-
+import html
from html.parser import HTMLParser
from django.utils.regex_helper import _lazy_re_compile
@@ -150,7 +150,10 @@ class Element:
output += ' %s' % key
if self.children:
output += '>\n'
- output += ''.join(str(c) for c in self.children)
+ output += ''.join([
+ html.escape(c) if isinstance(c, str) else str(c)
+ for c in self.children
+ ])
output += '\n</%s>' % self.name
else:
output += '>'
@@ -165,7 +168,10 @@ class RootElement(Element):
super().__init__(None, ())
def __str__(self):
- return ''.join(str(c) for c in self.children)
+ return ''.join([
+ html.escape(c) if isinstance(c, str) else str(c)
+ for c in self.children
+ ])
class HTMLParseError(Exception):