Opened 12 years ago
Closed 12 years ago
#20778 closed Bug (needsinfo)
label_tag() escapes lazy labels twice
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | 1.5 |
| Severity: | Normal | Keywords: | label_tag |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
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?