summaryrefslogtreecommitdiff
path: root/tests/forms_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/forms_tests')
-rw-r--r--tests/forms_tests/tests/test_forms.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index f2a77cb089..f06a31f393 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -2071,6 +2071,33 @@ class FormsTestCase(TestCase):
}
self.assertEqual(errors, control)
+ def test_error_dict_as_json_escape_html(self):
+ """#21962 - adding html escape flag to ErrorDict"""
+ class MyForm(Form):
+ foo = CharField()
+ bar = CharField()
+
+ def clean(self):
+ raise ValidationError('<p>Non-field error.</p>',
+ code='secret',
+ params={'a': 1, 'b': 2})
+
+ control = {
+ 'foo': [{'code': 'required', 'message': 'This field is required.'}],
+ 'bar': [{'code': 'required', 'message': 'This field is required.'}],
+ '__all__': [{'code': 'secret', 'message': '<p>Non-field error.</p>'}]
+ }
+
+ form = MyForm({})
+ self.assertFalse(form.is_valid())
+
+ errors = json.loads(form.errors.as_json())
+ self.assertEqual(errors, control)
+
+ errors = json.loads(form.errors.as_json(escape_html=True))
+ control['__all__'][0]['message'] = '&lt;p&gt;Non-field error.&lt;/p&gt;'
+ self.assertEqual(errors, control)
+
def test_error_list(self):
e = ErrorList()
e.append('Foo')