Ticket #6529: flatatt_with_conditional_escape.diff

File flatatt_with_conditional_escape.diff, 1.5 KB (added by Javier de la Rosa, 16 years ago)

Patch file and regression test.

  • django/forms/util.py

     
    1 from django.utils.html import escape
     1from django.utils.html import conditional_escape
    22from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode
    33from django.utils.safestring import mark_safe
    44
     
    99    XML-style pairs.  It is assumed that the keys do not need to be XML-escaped.
    1010    If the passed dictionary is empty, then return an empty string.
    1111    """
    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()])
    1313
    1414class ErrorDict(dict, StrAndUnicode):
    1515    """
  • tests/regressiontests/forms/util.py

     
    66tests = r"""
    77>>> from django.forms.util import *
    88>>> from django.utils.translation import ugettext_lazy
     9>>> from django.utils.safestring import mark_safe
    910
    1011###########
    1112# flatatt #
     
    1617u' id="header"'
    1718>>> flatatt({'class': "news", 'title': "Read this"})
    1819u' class="news" title="Read this"'
     20>>> flatatt({'onclick': mark_safe("javascript:{myFunction('string')}"), 'title': "Read this"})
     21u' onclick="javascript:{myFunction(\'string\')}" title="Read this"'
    1922>>> flatatt({})
    2023u''
    2124
Back to Top