summaryrefslogtreecommitdiff
path: root/django/test/html.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-05-09 06:55:32 -0700
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-05-09 15:55:32 +0200
commit48235ba807483fe349d2dc66aaeddc0d03f8b0d4 (patch)
tree1004a9f7399e7d1363b38f79f8cb1929835db9af /django/test/html.py
parentaf5ec222ccd24e81f9fec6c34836a4e503e7ccf7 (diff)
Refs #30399 -- Made assertHTMLEqual normalize character and entity references.
Diffstat (limited to 'django/test/html.py')
-rw-r--r--django/test/html.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/django/test/html.py b/django/test/html.py
index 8b064529b0..911872bb69 100644
--- a/django/test/html.py
+++ b/django/test/html.py
@@ -3,11 +3,14 @@
import re
from html.parser import HTMLParser
-WHITESPACE = re.compile(r'\s+')
+# ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020
+# SPACE.
+# https://infra.spec.whatwg.org/#ascii-whitespace
+ASCII_WHITESPACE = re.compile(r'[\t\n\f\r ]+')
def normalize_whitespace(string):
- return WHITESPACE.sub(' ', string)
+ return ASCII_WHITESPACE.sub(' ', string)
class Element:
@@ -144,7 +147,7 @@ class Parser(HTMLParser):
)
def __init__(self):
- super().__init__(convert_charrefs=False)
+ super().__init__()
self.root = RootElement()
self.open_tags = []
self.element_positions = {}
@@ -202,12 +205,6 @@ class Parser(HTMLParser):
def handle_data(self, data):
self.current.append(data)
- def handle_charref(self, name):
- self.current.append('&%s;' % name)
-
- def handle_entityref(self, name):
- self.current.append('&%s;' % name)
-
def parse_html(html):
"""