Ticket #16230: ticket16230.errordict_escaping.1.diff

File ticket16230.errordict_escaping.1.diff, 1.5 KB (added by Gregor Müllegger, 13 years ago)

Tests and Fix

  • django/forms/util.py

    diff --git a/django/forms/util.py b/django/forms/util.py
    index 1a1d823..85baffa 100644
    a b class ErrorDict(dict, StrAndUnicode):  
    2727    def as_ul(self):
    2828        if not self: return u''
    2929        return mark_safe(u'<ul class="errorlist">%s</ul>'
    30                 % ''.join([u'<li>%s%s</li>' % (k, force_unicode(v))
     30                % ''.join([u'<li>%s%s</li>' % (k, conditional_escape(force_unicode(v)))
    3131                    for k, v in self.items()]))
    3232
    3333    def as_text(self):
  • tests/regressiontests/forms/tests/util.py

    diff --git a/tests/regressiontests/forms/tests/util.py b/tests/regressiontests/forms/tests/util.py
    index 81fec1c..bb6ffd8 100644
    a b class FormsUtilTestCase(TestCase):  
    5555                         '<ul class="errorlist"><li>Example of link: &lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;</li></ul>')
    5656        self.assertEqual(str(ErrorList([mark_safe(example)])),
    5757                         '<ul class="errorlist"><li>Example of link: <a href="http://www.example.com/">example</a></li></ul>')
     58        self.assertEqual(str(ErrorDict({'name': example})),
     59                         '<ul class="errorlist"><li>nameExample of link: &lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;</li></ul>')
     60        self.assertEqual(str(ErrorDict({'name': mark_safe(example)})),
     61                         '<ul class="errorlist"><li>nameExample of link: <a href="http://www.example.com/">example</a></li></ul>')
Back to Top