From 3128f3d38d1db0bc01da9a4bf4be81119079d73a Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 18 Jun 2013 17:49:45 +0200 Subject: [PATCH] Fixed #20618 -- Fixed regression in `BoundField.label_tag`. --- django/forms/forms.py | 5 ++--- tests/forms_tests/tests/test_forms.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index e6a11f28fb..b25eeb30a4 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -518,9 +518,8 @@ class BoundField(object): """ contents = contents or self.label # Only add the suffix if the label does not end in punctuation. - if self.form.label_suffix: - if contents[-1] not in ':?.!': - contents = format_html('{0}{1}', contents, self.form.label_suffix) + if self.form.label_suffix and contents and contents[-1] not in ':?.!': + contents = format_html('{0}{1}', contents, self.form.label_suffix) widget = self.field.widget id_ = widget.attrs.get('id') or self.auto_id if id_: diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 3b722e5ac1..633fde5026 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1863,3 +1863,10 @@ class FormsTestCase(TestCase): form = SomeForm() self.assertHTMLEqual(form['custom'].label_tag(), '') self.assertHTMLEqual(form['empty'].label_tag(), '') + + def test_boundfield_empty_label(self): + class SomeForm(Form): + field = CharField(label='') + boundfield = SomeForm()['field'] + + self.assertHTMLEqual(boundfield.label_tag(), '')