Bug #51385

BooleanConverter considers "false" TRUE

Added by Bastian Waidelich about 8 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Should have
Category:
Property
Target version:
-
Start date:
2013-08-27
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

The BooleanConverter provided by Flow simply casts the $source to a boolean using boxing:

return (boolean)$source;

This leads to some weird inconsistencies, e.g. the string "false" returning TRUE.


Related issues

Related to TYPO3.Flow - Bug #59023: BooleanConverter should not convert empty values to booleanNew2014-05-22

Actions
Has duplicate TYPO3.Flow - Bug #51255: CommandController: Fix parsing of boolean valuesResolvedBastian Waidelich2013-08-22

Actions
#1

Updated by Gerrit Code Review about 8 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23355

#2

Updated by Timo Dödtmann about 8 years ago

The documentation (http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/CommandLine.html#passing-arguments) says following:
Possible values equivalent to TRUE are: on, 1, y, yes, true. Possible values equivalent to FALSE are: off, 0, n, no, false.

So, it must be something like that:
  • check (exactly) possible TRUE values (so, you can see FALSE as a fallback)
    if (is_bool($source)) {
        return $source;
    }
    return (!empty($source) && in_array(strtolower($source), array('on', '1', 'y', 'yes', 'true')));
    
  • check (exactly) possible FALSE values (so, you can see TRUE as a fallback)
    if (is_bool($source)) {
        return $source;
    }
    return (!empty($source) && !in_array(strtolower($source), array('off', '0', 'n', 'no', 'false')));
    
#3

Updated by Gerrit Code Review about 8 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23355

#4

Updated by Bastian Waidelich about 8 years ago

Timo Dödtmann wrote:

The documentation (http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/CommandLine.html#passing-arguments) says following:
Possible values equivalent to TRUE are: on, 1, y, yes, true. Possible values equivalent to FALSE are: off, 0, n, no, false.

good point. See PS#2 at https://review.typo3.org/23355 and feel free to test/vote for the patch

#5

Updated by Bastian Waidelich almost 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#6

Updated by Gerrit Code Review over 7 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch 2.0 of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/27205

#7

Updated by Bastian Waidelich over 7 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF