| 2220 | Validation errors are escaped when output to html |
| 2221 | >>> class EscapingForm(Form): |
| 2222 | ... special_name = CharField() |
| 2223 | ... def clean_special_name(self): |
| 2224 | ... special_name = self.clean_data['special_name'] |
| 2225 | ... raise ValidationError("Something wrong with '%s'" % special_name) |
| 2226 | |
| 2227 | >>> f = EscapingForm({'special_name': "Nothing to escape"}) |
| 2228 | >>> print f |
| 2229 | <tr><th><label for="id_special_name">Special name:</label></th><td><ul class="errorlist"><li>Something wrong with 'Nothing to escape'</li></ul><input type="text" name="special_name" value="Nothing to escape" id="id_special_name" /></td></tr> |
| 2230 | >>> f = EscapingForm({'special_name': "Should escape < & > and <script>alert('xss')</script>"}) |
| 2231 | >>> print f |
| 2232 | <tr><th><label for="id_special_name">Special name:</label></th><td><ul class="errorlist"><li>Something wrong with 'Should escape < & > and <script>alert('xss')</script>'</li></ul><input type="text" name="special_name" value="Should escape < & > and <script>alert('xss')</script>" id="id_special_name" /></td></tr> |
| 2233 | |