[Django] #20778: label_tag() escapes lazy labels twice

4 views
Skip to first unread message

Django

unread,
Jul 19, 2013, 3:29:13 PM7/19/13
to django-...@googlegroups.com
#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 &amp;#39;label&amp;#39;</label>`

The expected behaviour would be to get the contents escaped but only once:

`<label>My &#39;label&#39;</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.

Django

unread,
Jul 25, 2013, 11:56:05 AM7/25/13
to django-...@googlegroups.com
#20778: label_tag() escapes lazy labels twice
---------------------------+--------------------------------------
Reporter: sephi@… | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.5
Severity: Normal | Resolution: needsinfo

Keywords: label_tag | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by timo):

* status: new => closed
* needs_better_patch: => 0
* resolution: => needsinfo
* needs_tests: => 0
* needs_docs: => 0


Comment:

I can't reproduce this on master or 1.5.x. Perhaps you could provide a
test case for Django's test suite that demonstrates the problem?

--
Ticket URL: <https://code.djangoproject.com/ticket/20778#comment:1>

Reply all
Reply to author
Forward
0 new messages