Ticket #6529: flatatt_with_conditional_escape.diff
File flatatt_with_conditional_escape.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/forms/util.py
1 from django.utils.html import escape1 from django.utils.html import conditional_escape 2 2 from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode 3 3 from django.utils.safestring import mark_safe 4 4 … … 9 9 XML-style pairs. It is assumed that the keys do not need to be XML-escaped. 10 10 If the passed dictionary is empty, then return an empty string. 11 11 """ 12 return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])12 return u''.join([u' %s="%s"' % (k, conditional_escape(v)) for k, v in attrs.items()]) 13 13 14 14 class ErrorDict(dict, StrAndUnicode): 15 15 """ -
tests/regressiontests/forms/util.py
6 6 tests = r""" 7 7 >>> from django.forms.util import * 8 8 >>> from django.utils.translation import ugettext_lazy 9 >>> from django.utils.safestring import mark_safe 9 10 10 11 ########### 11 12 # flatatt # … … 16 17 u' id="header"' 17 18 >>> flatatt({'class': "news", 'title': "Read this"}) 18 19 u' class="news" title="Read this"' 20 >>> flatatt({'onclick': mark_safe("javascript:{myFunction('string')}"), 'title': "Read this"}) 21 u' onclick="javascript:{myFunction(\'string\')}" title="Read this"' 19 22 >>> flatatt({}) 20 23 u'' 21 24