#20778: label_tag() escapes lazy labels twice
----------------------------+-----------------------
Reporter: sephi@… | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Keywords: label_tag
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-----------------------
If you use label_tag() on a field that uses a ugettext_lazy() string as a
label, it gets escaped twice. That's easily reproducible with the
following code:
models.py
{{{
# _ is ugettext_lazy
class MyModel(models.Model):
name = models.CharField(_('My label'))
}}}
forms.py
{{{
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
}}}
views.py
{{{
def my_view(request):
myform = MyForm()
assert False, myform['name'].label_tag()
}}}
If "My label" is translated as "My 'label'" (with single quotes around
it), here's what you get:
`<label>My &#39;label&#39;</label>`
The expected behaviour would be to get the contents escaped but only once:
`<label>My 'label'</label>`
That would then appear correctly in the template. Also if you use a simple
string as a label in your model, it gets escaped correctly.
--
Ticket URL: <https://code.djangoproject.com/ticket/20778>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.587d5aa52b285f24ebe6ddcdfec5dfd0%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.