From 8ce352c21d9ce4c59fcd259103350772954a6f8e Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 3 May 2011 11:52:30 +0000 Subject: [PATCH] Fixed #13770 -- Extended BooleanField form field to also clean `u'false'` to `False`. Thanks, jordanb and Claude Paroz. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16148 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/fields.py | 2 +- tests/regressiontests/forms/tests/fields.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django/forms/fields.py b/django/forms/fields.py index e3299c07aa..a5ea81d4b6 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -605,7 +605,7 @@ class BooleanField(Field): # will submit for False. Also check for '0', since this is what # RadioSelect will provide. Because bool("True") == bool('1') == True, # we don't need to handle that explicitly. - if value in ('False', '0'): + if isinstance(value, basestring) and value.lower() in ('false', '0'): value = False else: value = bool(value) diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index 59c761c76d..2303b4e9db 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -698,6 +698,8 @@ class FieldsTests(TestCase): self.assertEqual(False, f.clean('0')) self.assertEqual(True, f.clean('Django rocks')) self.assertEqual(False, f.clean('False')) + self.assertEqual(False, f.clean('false')) + self.assertEqual(False, f.clean('FaLsE')) # ChoiceField #################################################################