diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2020-02-10 22:40:07 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-02-13 08:12:44 +0100 |
| commit | 49275c548887769cd70bbd85a3b125491f0c4062 (patch) | |
| tree | 4c954838fa6bdd8f568c69077ca357978338bf89 /tests | |
| parent | da4923ea87124102aae4455e947ce24599c0365b (diff) | |
Fixed #30261 -- Prevented Form._html_output() from mutating errors if hidden fields have errors.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index e4a8127e15..b62b32de4b 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1245,6 +1245,22 @@ value="Should escape < & > and <script>alert('xss')< self.assertTrue(f.has_error(NON_FIELD_ERRORS, 'password_mismatch')) self.assertFalse(f.has_error(NON_FIELD_ERRORS, 'anything')) + def test_html_output_with_hidden_input_field_errors(self): + class TestForm(Form): + hidden_input = CharField(widget=HiddenInput) + + def clean(self): + self.add_error(None, 'Form error') + + f = TestForm(data={}) + error_dict = { + 'hidden_input': ['This field is required.'], + '__all__': ['Form error'], + } + self.assertEqual(f.errors, error_dict) + f.as_table() + self.assertEqual(f.errors, error_dict) + def test_dynamic_construction(self): # It's possible to construct a Form dynamically by adding to the self.fields # dictionary in __init__(). Don't forget to call Form.__init__() within the |
