Ticket #16684: 16684.diff

File 16684.diff, 1.8 KB (added by dtrebbien, 4 years ago)

Patch with regression test

  • tests/regressiontests/forms/tests/regressions.py

    class FormsRegressionsTestCase(TestCase): 
    1818
    1919        self.assertEqual(TestForm(auto_id=False).as_p(), u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>')
    2020
     21    def test_regression_16684(self):
     22        """
     23        Test for bug #16684 - make sure to escape CSS class identifiers
     24        """
     25        class TestForm(Form):
     26            required_css_class = r'\&required'
     27
     28            text = CharField()
     29
     30        form = TestForm({ 'text': 'test' })
     31        self.assertEqual(unicode(form.as_table()), u'<tr class="\\&amp;required"><th><label for="id_text">Text:</label></th><td><input type="text" name="text" value="test" id="id_text" /></td></tr>')
     32
    2133    def test_regression_3600(self):
    2234        # Tests for form i18n #
    2335        # There were some problems with form translations in #3600
  • django/forms/forms.py

    class BaseForm(StrAndUnicode): 
    153153                # CSS classes applied.
    154154                css_classes = bf.css_classes()
    155155                if css_classes:
    156                     html_class_attr = ' class="%s"' % css_classes
     156                    html_class_attr = ' class="%s"' % conditional_escape(css_classes)
    157157
    158158                if errors_on_separate_row and bf_errors:
    159159                    output.append(error_row % force_unicode(bf_errors))
Back to Top