diff options
| author | Daniil <daniilr@users.noreply.github.com> | 2017-12-11 22:30:47 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-12-11 07:30:47 -0500 |
| commit | 7c7bc6391a3e83566f9ace59955e63503bc76cee (patch) | |
| tree | 91ea930d8288f33c2ce977d58de3368229066875 | |
| parent | d13a9e44ded4e93570c6ba42ec84e45ddca2505b (diff) | |
Fixed #28874 -- Prevented double escaping of errors on hidden form fields.
| -rw-r--r-- | django/forms/forms.py | 3 | ||||
| -rw-r--r-- | tests/forms_tests/tests/test_forms.py | 21 |
2 files changed, 22 insertions, 2 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index a43f80996b..d8a05e3583 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -199,8 +199,7 @@ class BaseForm: for name, field in self.fields.items(): html_class_attr = '' bf = self[name] - # Escape and cache in local variable. - bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) + bf_errors = self.error_class(bf.errors) if bf.is_hidden: if bf_errors: top_errors.extend( diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 3f4fb4e10b..a6b157f044 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -3398,6 +3398,27 @@ Good luck picking a username that doesn't already exist.</p> <div class="errorlist"><div class="error">This field is required.</div></div> <p>Comment: <input type="text" name="comment" required /></p>""") + def test_error_escaping(self): + class TestForm(Form): + hidden = CharField(widget=HiddenInput(), required=False) + visible = CharField() + + def clean_hidden(self): + raise ValidationError('Foo & "bar"!') + + clean_visible = clean_hidden + + form = TestForm({'hidden': 'a', 'visible': 'b'}) + form.is_valid() + self.assertHTMLEqual( + form.as_ul(), + '<li><ul class="errorlist nonfield"><li>(Hidden field hidden) Foo & "bar"!</li></ul></li>' + '<li><ul class="errorlist"><li>Foo & "bar"!</li></ul>' + '<label for="id_visible">Visible:</label> ' + '<input type="text" name="visible" value="b" id="id_visible" required />' + '<input type="hidden" name="hidden" value="a" id="id_hidden" /></li>' + ) + def test_baseform_repr(self): """ BaseForm.__repr__() should contain some basic information about the |
