From b7a33ee4f0f20e5b7e3dcd72d9b0c4c342c7f147 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 9 May 2019 08:18:18 -0700 Subject: [PATCH] Fixed #30468 -- Fixed assertHTMLEqual() to handle all ASCII whitespace in a class attribute. --- django/test/html.py | 2 +- tests/test_utils/tests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/django/test/html.py b/django/test/html.py index 911872bb690..b238fd48d9c 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 c14746f3443..2697590b774 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 = [ (''', '''),