Opened 14 years ago

Closed 13 years ago

#13770 closed Bug (fixed)

form BooleanField should clean the string u'false' as False.

Reported by: jordanb Owned by: nobody
Component: Forms Version: 1.1
Severity: Normal Keywords:
Cc: dmclain Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I ran into this trying to assign a JavaScript Boolean false to a HiddenInput widget in a BooleanField. The browser submitted that as u'false', which is cleaned to True by the BooleanField because it only recognizes u"False" or u"0" as valid string-forms of false.

The supplied patch changes the comparison to be case insensitive, so "False", "FALSE", "false", "FaLsE" all work, which is the sensible way to handle it I think.

Note that the patch is for version 1.1 but the behavior exists in SVN as well, with the only difference being line numbers.

Attachments (2)

case_insensitive_boolean.patch (838 bytes ) - added by jordanb 14 years ago.
Patch for case-insensitive cleaning in boolean field for django 1.1.1
13770-1.diff (1.2 KB ) - added by Claude Paroz 13 years ago.
Patch including tests

Download all attachments as: .zip

Change History (10)

by jordanb, 14 years ago

Patch for case-insensitive cleaning in boolean field for django 1.1.1

comment:1 by Matthias Kestenholz, 13 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

I think this feature makes sense. However, we still need tests for this.

comment:2 by pma_, 13 years ago

Has patch: unset
Needs tests: unset
Version: 1.11.2

similar problem found in 1.2.3. BooleanField is returned by browser as u'false' but cleaned data shows value as type bool with false value what is absolutely incorrect.

comment:3 by Matthias Kestenholz, 13 years ago

Needs tests: set
Patch needs improvement: set
Version: 1.21.1

This behavior existed in 1.1 already, changing version back to 1.1.

This feature _does_ need tests. The patch should be attached in unidiff format. Marking as such again.

comment:4 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

by Claude Paroz, 13 years ago

Attachment: 13770-1.diff added

Patch including tests

comment:5 by Claude Paroz, 13 years ago

Easy pickings: unset
Has patch: set
Needs tests: unset
Patch needs improvement: unset

comment:6 by dmclain, 13 years ago

Triage Stage: AcceptedReady for checkin

Looks good to me

comment:7 by dmclain, 13 years ago

Cc: dmclain added

comment:8 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16148]:

Fixed #13770 -- Extended BooleanField form field to also clean u'false' to False. Thanks, jordanb and Claude Paroz.

Note: See TracTickets for help on using tickets.
Back to Top