From 27c98d6ab381e5954c0b2f977b8247f3b457e7fe Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 21 Apr 2015 16:25:27 +0100 Subject: [PATCH 1/2] failing test for whitelisting of DIV elements --- wagtail/wagtailcore/tests/test_dbwhitelister.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wagtail/wagtailcore/tests/test_dbwhitelister.py b/wagtail/wagtailcore/tests/test_dbwhitelister.py index 35e5b34b5e..3ab7868fa5 100644 --- a/wagtail/wagtailcore/tests/test_dbwhitelister.py +++ b/wagtail/wagtailcore/tests/test_dbwhitelister.py @@ -36,6 +36,13 @@ class TestDbWhitelister(TestCase): expected = '

OMG look at this video of a kitten:

' self.assertHtmlEqual(expected, output_html) + def test_div_conversion(self): + # DIVs should be converted to P, and all whitelist / conversion rules still applied + input_html = '

before

OMG look at this video of a kitten:

after

' + output_html = DbWhitelister.clean(input_html) + expected = '

before

OMG look at this video of a kitten:

after

' + self.assertHtmlEqual(expected, output_html) + def test_whitelist_hooks(self): # wagtail.tests.wagtail_hooks overrides the whitelist to permit
and input_html = '
I would put a tax on all people who stand in water.

- Gumby

' From fe4741e4e345323cae0fe4517cd544b61108fa78 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 21 Apr 2015 16:27:42 +0100 Subject: [PATCH 2/2] Do not skip whitelisting when converting 'div' elements to 'p' --- wagtail/wagtailcore/rich_text.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailcore/rich_text.py b/wagtail/wagtailcore/rich_text.py index d4ac8d6561..60159ca5ca 100644 --- a/wagtail/wagtailcore/rich_text.py +++ b/wagtail/wagtailcore/rich_text.py @@ -127,9 +127,10 @@ class DbWhitelister(Whitelister): link_attrs['linktype'] = link_type tag.attrs.clear() tag.attrs.update(**link_attrs) - elif tag.name == 'div': - tag.name = 'p' else: + if tag.name == 'div': + tag.name = 'p' + super(DbWhitelister, cls).clean_tag_node(doc, tag)