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 15:35:31 +0100
commit4c60c3edff4312303e1021fca47ed52c2152d285 (patch)
tree8059777872dfd70986f35768e6a80664c79e3dc8 /tests/forms_tests
parentbdf3e156b4b47d45b8e37823164b598afc533ce0 (diff)
downloaddjango-4c60c3edff4312303e1021fca47ed52c2152d285.tar.gz
Fixed #33419 -- Restored marking forms.Field.help_text as HTML safe.
Regression in 456466d932830b096d39806e291fe23ec5ed38d5. Thanks Matt Westcott for the report.
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 5c653fb492..aa47481998 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -2326,6 +2326,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