Fixed #30468 -- Fixed assertHTMLEqual() to handle all ASCII whitespace in a class attribute.

This commit is contained in:
Jon Dufresne 2019-05-09 08:18:18 -07:00 committed by Carlton Gibson
parent de6d3afb97
commit b7a33ee4f0
2 changed files with 15 additions and 1 deletions

View File

@ -180,7 +180,7 @@ class Parser(HTMLParser):
# Special case handling of 'class' attribute, so that comparisons of DOM # Special case handling of 'class' attribute, so that comparisons of DOM
# instances are not sensitive to ordering of classes. # instances are not sensitive to ordering of classes.
attrs = [ attrs = [
(name, " ".join(sorted(value.split(" ")))) (name, ' '.join(sorted(value for value in ASCII_WHITESPACE.split(value) if value)))
if name == "class" if name == "class"
else (name, value) else (name, value)
for name, value in attrs for name, value in attrs

View File

@ -613,6 +613,20 @@ class HTMLEqualTests(SimpleTestCase):
'<input type="text" id="id_name" />', '<input type="text" id="id_name" />',
'<input type="password" id="id_name" />') '<input type="password" id="id_name" />')
def test_class_attribute(self):
pairs = [
('<p class="foo bar"></p>', '<p class="bar foo"></p>'),
('<p class=" foo bar "></p>', '<p class="bar foo"></p>'),
('<p class=" foo bar "></p>', '<p class="bar foo"></p>'),
('<p class="foo\tbar"></p>', '<p class="bar foo"></p>'),
('<p class="\tfoo\tbar\t"></p>', '<p class="bar foo"></p>'),
('<p class="\t\t\tfoo\t\t\tbar\t\t\t"></p>', '<p class="bar foo"></p>'),
('<p class="\t \nfoo \t\nbar\n\t "></p>', '<p class="bar foo"></p>'),
]
for html1, html2 in pairs:
with self.subTest(html1):
self.assertHTMLEqual(html1, html2)
def test_normalize_refs(self): def test_normalize_refs(self):
pairs = [ pairs = [
('&#39;', '&#x27;'), ('&#39;', '&#x27;'),