Ticket #9111: safestring-tests-r9066.diff

File safestring-tests-r9066.diff, 2.3 KB (added by Ivan Giuliani, 16 years ago)
  • tests/regressiontests/forms/forms.py

     
    595595Validation errors are HTML-escaped when output as HTML.
    596596>>> class EscapingForm(Form):
    597597...     special_name = CharField()
     598...     special_safe_name = CharField()
    598599...     def clean_special_name(self):
    599600...         raise ValidationError("Something's wrong with '%s'" % self.cleaned_data['special_name'])
     601...     def clean_special_safe_name(self):
     602...         from django.utils.safestring import mark_safe
     603...         raise ValidationError(mark_safe("'<b>%s</b>' is a safe string" % self.cleaned_data['special_safe_name']))
    600604
    601 >>> f = EscapingForm({'special_name': "Nothing to escape"}, auto_id=False)
     605>>> f = EscapingForm({'special_name': "Nothing to escape", 'special_safe_name': "Nothing to escape"}, auto_id=False)
    602606>>> print f
    603607<tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Nothing to escape&#39;</li></ul><input type="text" name="special_name" value="Nothing to escape" /></td></tr>
    604 >>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}, auto_id=False)
     608<tr><th>Special safe name:</th><td><ul class="errorlist"><li>'<b>Nothing to escape</b>' is a safe string</li></ul><input type="text" name="special_safe_name" value="Nothing to escape" /></td></tr>
     609>>> f = EscapingForm(
     610...     {'special_name': "Should escape < & > and <script>alert('xss')</script>",
     611...     'special_safe_name': "<i>Do not escape</i>"}, auto_id=False)
    605612>>> print f
    606613<tr><th>Special name:</th><td><ul class="errorlist"><li>Something&#39;s wrong with &#39;Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;&#39;</li></ul><input type="text" name="special_name" value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;" /></td></tr>
     614<tr><th>Special safe name:</th><td><ul class="errorlist"><li>'<b><i>Do not escape</i></b>' is a safe string</li></ul><input type="text" name="special_safe_name" value="&lt;i&gt;Do not escape&lt;/i&gt;" /></td></tr>
    607615
    608616""" + \
    609617r""" # [This concatenation is to keep the string below the jython's 32K limit].
Back to Top