diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-05-09 08:18:18 -0700 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-05-09 17:18:18 +0200 |
| commit | b7a33ee4f0f20e5b7e3dcd72d9b0c4c342c7f147 (patch) | |
| tree | 7205c7818abb7c168914f83190d8da8cfc003974 | |
| parent | de6d3afb97454e0653d55adadcf0df7e2a03c088 (diff) | |
Fixed #30468 -- Fixed assertHTMLEqual() to handle all ASCII whitespace in a class attribute.
| -rw-r--r-- | django/test/html.py | 2 | ||||
| -rw-r--r-- | tests/test_utils/tests.py | 14 |
2 files changed, 15 insertions, 1 deletions
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): '<input type="text" 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): pairs = [ (''', '''), |
