Code

Opened 4 years ago

Closed 3 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 4 years ago.
Patch for case-insensitive cleaning in boolean field for django 1.1.1
13770-1.diff (1.2 KB) - added by claudep 3 years ago.
Patch including tests

Download all attachments as: .zip

Change History (10)

Changed 4 years ago by jordanb

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

comment:1 Changed 4 years ago by mk

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 4 years ago by pma_

  • Has patch unset
  • Needs tests unset
  • Version changed from 1.1 to 1.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 4 years ago by mk

  • Needs tests set
  • Patch needs improvement set
  • Version changed from 1.2 to 1.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 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 3 years ago by claudep

Patch including tests

comment:5 Changed 3 years ago by claudep

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

comment:6 Changed 3 years ago by dmclain

  • Triage Stage changed from Accepted to Ready for checkin

Looks good to me

comment:7 Changed 3 years ago by dmclain

  • Cc dmclain added

comment:8 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16148]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.