summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
authorDavid <smithdc@gmail.com>2022-01-07 07:46:55 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-01-07 16:12:15 +0100
commitc959aa99aa365c123a3b5ca72df9d07e0e3fe6e5 (patch)
tree8393d09f5c4f9856259ee16e03ca7b8048e22b23 /tests/forms_tests
parent11475958f6c1aca61638c476cc314ec0410161dc (diff)
[4.0.x] Fixed #33419 -- Restored marking forms.Field.help_text as HTML safe.
Regression in 456466d932830b096d39806e291fe23ec5ed38d5. Thanks Matt Westcott for the report. Backport of 4c60c3edff4312303e1021fca47ed52c2152d285 from main
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index c478a71699..aa283d53c7 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -2252,6 +2252,41 @@ Password: <input type="password" name="password" required>
<input type="hidden" name="next" value="/"></li>"""
)
+ def test_help_text_html_safe(self):
+ """help_text should not be escaped."""
+ class UserRegistration(Form):
+ username = CharField(max_length=10, help_text='e.g., user@example.com')
+ password = CharField(
+ widget=PasswordInput,
+ help_text='Help text is <strong>escaped</strong>.',
+ )
+
+ p = UserRegistration(auto_id=False)
+ self.assertHTMLEqual(
+ p.as_ul(),
+ '<li>Username: <input type="text" name="username" maxlength="10" required>'
+ '<span class="helptext">e.g., user@example.com</span></li>'
+ '<li>Password: <input type="password" name="password" required>'
+ '<span class="helptext">Help text is <strong>escaped</strong>.</span></li>'
+ )
+ self.assertHTMLEqual(
+ p.as_p(),
+ '<p>Username: <input type="text" name="username" maxlength="10" required>'
+ '<span class="helptext">e.g., user@example.com</span></p>'
+ '<p>Password: <input type="password" name="password" required>'
+ '<span class="helptext">Help text is <strong>escaped</strong>.</span></p>'
+ )
+ self.assertHTMLEqual(
+ p.as_table(),
+ '<tr><th>Username:</th><td>'
+ '<input type="text" name="username" maxlength="10" required><br>'
+ '<span class="helptext">e.g., user@example.com</span></td></tr>'
+ '<tr><th>Password:</th><td>'
+ '<input type="password" name="password" required><br>'
+ '<span class="helptext">Help text is <strong>escaped</strong>.</span>'
+ '</td></tr>'
+ )
+
def test_subclassing_forms(self):
# You can subclass a Form to add fields. The resulting form subclass will have
# all of the fields of the parent Form, plus whichever fields you define in the