Ticket #6283: forms.patch

File forms.patch, 2.8 KB (added by Paul Hummer, 17 years ago)

Patch to fix issue 6283

  • fields.py

     
    1818
    1919from django.utils.translation import ugettext_lazy as _
    2020from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str
     21from django.utils.safestring import mark_safe
    2122
    2223from util import ErrorList, ValidationError
    2324from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput
     
    6667        # help_text -- An optional string to use as "help text" for this Field.
    6768        if label is not None:
    6869            label = smart_unicode(label)
    69         self.required, self.label, self.initial = required, label, initial
     70        self.required, self.label, self.initial = required, mark_safe(label), initial
    7071        self.help_text = smart_unicode(help_text or '')
    7172        widget = widget or self.widget
    7273        if isinstance(widget, type):
  • forms.py

     
    55from copy import deepcopy
    66
    77from django.utils.datastructures import SortedDict
    8 from django.utils.html import escape
     8from django.utils.html import conditional_escape
    99from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode
    1010from django.utils.safestring import mark_safe
    1111
     
    109109        output, hidden_fields = [], []
    110110        for name, field in self.fields.items():
    111111            bf = BoundField(self, field, name)
    112             bf_errors = self.error_class([escape(error) for error in bf.errors]) # Escape and cache in local variable.
     112            bf_errors = self.error_class([conditional_escape(error) for error in bf.errors]) # Escape and cache in local variable.
    113113            if bf.is_hidden:
    114114                if bf_errors:
    115115                    top_errors.extend(['(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
     
    118118                if errors_on_separate_row and bf_errors:
    119119                    output.append(error_row % force_unicode(bf_errors))
    120120                if bf.label:
    121                     label = escape(force_unicode(bf.label))
     121                    label = conditional_escape(force_unicode(bf.label))
    122122                    # Only add the suffix if the label does not end in
    123123                    # punctuation.
    124124                    if self.label_suffix:
     
    302302
    303303        If attrs are given, they're used as HTML attributes on the <label> tag.
    304304        """
    305         contents = contents or escape(self.label)
     305        contents = contents or conditional_escape(self.label)
    306306        widget = self.field.widget
    307307        id_ = widget.attrs.get('id') or self.auto_id
    308308        if id_:
Back to Top