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(), '')