Opened 6 years ago

Closed 6 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:

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 6 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 6 years ago.
Patch including tests

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by jordanb

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

comment:1 Changed 6 years ago by Matthias Kestenholz

Needs tests: set
Triage Stage: UnreviewedAccepted

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

comment:2 Changed 6 years ago by pma_

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 Changed 6 years ago by Matthias Kestenholz

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 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

Changed 6 years ago by Claude Paroz

Attachment: 13770-1.diff added

Patch including tests

comment:5 Changed 6 years ago by Claude Paroz

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

comment:6 Changed 6 years ago by dmclain

Triage Stage: AcceptedReady for checkin

Looks good to me

comment:7 Changed 6 years ago by dmclain

Cc: dmclain added

comment:8 Changed 6 years ago by Jannis Leidel

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