diff --git a/django/test/html.py b/django/test/html.py index 911872bb69..b238fd48d9 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -180,7 +180,7 @@ class Parser(HTMLParser): # Special case handling of 'class' attribute, so that comparisons of DOM # instances are not sensitive to ordering of classes. attrs = [ - (name, " ".join(sorted(value.split(" ")))) + (name, ' '.join(sorted(value for value in ASCII_WHITESPACE.split(value) if value))) if name == "class" else (name, value) for name, value in attrs diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index c14746f344..2697590b77 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -613,6 +613,20 @@ class HTMLEqualTests(SimpleTestCase): '', '') + def test_class_attribute(self): + pairs = [ + ('
', ''), + ('', ''), + ('', ''), + ('', ''), + ('', ''), + ('', ''), + ('', ''), + ] + for html1, html2 in pairs: + with self.subTest(html1): + self.assertHTMLEqual(html1, html2) + def test_normalize_refs(self): pairs = [ (''', '''),