Skip to content

Commit 882a4a3

Browse files
committed
fix: Preserve aria and role attributes
1 parent 2260ec4 commit 882a4a3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

djangocms_text/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __call__(self) -> dict[str, Union[dict[str, set[str]], set[str], None]]:
8181
"cms-plugin": {"id", "title", "name", "alt", "render-plugin", "type"},
8282
"*": {"style", "class"},
8383
},
84-
generic_attribute_prefixes={"data-"},
84+
generic_attribute_prefixes={"data-", "aria-", "role-"},
8585
)
8686
#: An instance of NH3Parser with the default configuration for CMS text content.
8787

tests/test_html.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ def test_clean_html_with_sanitize_disabled(self):
9999
finally:
100100
settings.TEXT_HTML_SANITIZE = old_text_html_sanitize
101101

102+
def test_clean_html_preserves_aria_attributes(self):
103+
original = '<span aria-label="foo">foo</span>'
104+
cleaned = html.clean_html(
105+
original,
106+
full=False,
107+
)
108+
self.assertHTMLEqual(original, cleaned)
109+
110+
def test_clean_html_preserves_data_attributes(self):
111+
original = '<span data-test-attr="foo">foo</span>'
112+
cleaned = html.clean_html(
113+
original,
114+
full=False,
115+
)
116+
self.assertHTMLEqual(original, cleaned)
117+
118+
def test_clean_html_preserves_role_attribute(self):
119+
original = '<span role="button">foo</span>'
120+
cleaned = html.clean_html(
121+
original,
122+
full=False,
123+
)
124+
self.assertHTMLEqual(original, cleaned)
125+
102126

103127
class HTMLDynamicAttriutesTest(TestFixture, CMSTestCase):
104128
def test_dynamic_link(self):

0 commit comments

Comments
 (0)