Ticket #13770: 13770-1.diff

File 13770-1.diff, 1.2 KB (added by Claude Paroz, 14 years ago)

Patch including tests

  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index c61fca1..03ccd25 100644
    a b class BooleanField(Field):  
    601601        # will submit for False. Also check for '0', since this is what
    602602        # RadioSelect will provide. Because bool("True") == bool('1') == True,
    603603        # we don't need to handle that explicitly.
    604         if value in ('False', '0'):
     604        if isinstance(value, basestring) and value.lower() in ('false', '0'):
    605605            value = False
    606606        else:
    607607            value = bool(value)
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index f76e732..100e63d 100644
    a b class FieldsTests(TestCase):  
    663663        self.assertEqual(False, f.clean('0'))
    664664        self.assertEqual(True, f.clean('Django rocks'))
    665665        self.assertEqual(False, f.clean('False'))
     666        self.assertEqual(False, f.clean('false'))
     667        self.assertEqual(False, f.clean('FaLsE'))
    666668
    667669    # ChoiceField #################################################################
    668670
Back to Top