Ticket #6474: utils_conditional_escape.diff
File utils_conditional_escape.diff, 1.4 KB (added by , 17 years ago) |
---|
-
django/utils/html.py
38 38 """ 39 39 if isinstance(html, SafeData): 40 40 return html 41 html = force_unicode(html) 42 if isinstance(html, SafeData): 43 return html 41 44 else: 42 45 return escape(html) 43 46 -
tests/regressiontests/utils/tests.py
5 5 from unittest import TestCase 6 6 7 7 from django.utils import html, checksums 8 from django.utils.safestring import mark_safe 8 9 9 10 import timesince 10 11 import datastructures … … 45 46 # Verify it doesn't double replace &. 46 47 self.check_output(f, '<&', '<&') 47 48 49 def test_conditional_escape(self): 50 class BoldHTML(object): 51 def __init__(self, content): 52 self.content = content 53 def __unicode__(self): 54 return mark_safe(u'<b>%s</b>' % f(self.content)) 55 f = html.conditional_escape 56 b = BoldHTML('a') 57 self.check_output(f, b, '<b>a</b>') 58 b = BoldHTML('<>') 59 self.check_output(f, b, '<b><></b>') 60 48 61 def test_linebreaks(self): 49 62 f = html.linebreaks 50 63 items = (