Ticket #6160: validation-escaping.5.diff
File validation-escaping.5.diff, 4.9 KB (added by , 16 years ago) |
---|
-
django/contrib/auth/tests/views.py
=== modified file 'django/contrib/auth/tests/views.py'
16 16 response = self.client.get('/password_reset/') 17 17 self.assertEquals(response.status_code, 200) 18 18 response = self.client.post('/password_reset/', {'email': 'not_a_real_email@email.com'}) 19 self.assertContains(response, "That e-mail address doesn 't have an associated user account")19 self.assertContains(response, "That e-mail address doesn't have an associated user account") 20 20 self.assertEquals(len(mail.outbox), 0) 21 21 22 22 def test_email_found(self): … … 87 87 response = self.client.post(path, {'new_password1': 'anewpassword', 88 88 'new_password2':' x'}) 89 89 self.assertEquals(response.status_code, 200) 90 self.assert_("The two password fields didn 't match" in response.content)90 self.assert_("The two password fields didn't match" in response.content) 91 91 92 92 93 93 class ChangePasswordTest(TestCase): … … 147 147 } 148 148 ) 149 149 self.assertEquals(response.status_code, 200) 150 self.assert_("The two password fields didn 't match." in response.content)150 self.assert_("The two password fields didn't match." in response.content) 151 151 152 152 def test_password_change_succeeds(self): 153 153 self.login() -
django/forms/forms.py
=== modified file 'django/forms/forms.py'
5 5 from copy import deepcopy 6 6 7 7 from django.utils.datastructures import SortedDict 8 from django.utils.html import escape 8 from django.utils.html import escape, conditional_escape 9 9 from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode 10 10 from django.utils.safestring import mark_safe 11 11 … … 134 134 output, hidden_fields = [], [] 135 135 for name, field in self.fields.items(): 136 136 bf = BoundField(self, field, name) 137 bf_errors = self.error_class([ escape(error) for error in bf.errors]) # Escape and cache in local variable.137 bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable. 138 138 if bf.is_hidden: 139 139 if bf_errors: 140 140 top_errors.extend([u'(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors]) -
django/forms/util.py
=== modified file 'django/forms/util.py'
39 39 def as_ul(self): 40 40 if not self: return u'' 41 41 return mark_safe(u'<ul class="errorlist">%s</ul>' 42 % ''.join([u'<li>%s</li>' % force_unicode(e) for e in self]))42 % ''.join([u'<li>%s</li>' % conditional_escape(force_unicode(e)) for e in self])) 43 43 44 44 def as_text(self): 45 45 if not self: return u'' -
tests/regressiontests/forms/util.py
=== modified file 'tests/regressiontests/forms/util.py'
49 49 # Can take a non-string. 50 50 >>> print ValidationError(VeryBadError()).messages 51 51 <ul class="errorlist"><li>A very bad error.</li></ul> 52 53 # Can escape and conditional escape. 54 55 >>> from django.utils.html import escape, conditional_escape 56 >>> example = 'Example of link: <a href="http://www.example.com/">example</a>' 57 58 >>> print ValidationError(example).messages 59 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 60 >>> print ValidationError(escape(example)).messages 61 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 62 >>> print ValidationError(conditional_escape(example)).messages 63 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 64 >>> print ValidationError(mark_safe(example)).messages 65 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 66 67 >>> print conditional_escape(unicode(ValidationError(example).messages)) 68 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 69 >>> print conditional_escape(unicode(ValidationError(escape(example)).messages)) 70 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 71 >>> print conditional_escape(unicode(ValidationError(conditional_escape(example)).messages)) 72 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 73 >>> print conditional_escape(unicode(ValidationError(mark_safe(example)).messages)) 74 <ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul> 52 75 """