Bug #51255

CommandController: Fix parsing of boolean values

Added by Timo Dödtmann almost 2 years ago. Updated about 1 year ago.

Status:Resolved Start date:2013-08-22
Priority:Should have Due date:
Assigned To:Bastian Waidelich % Done:

0%

Category:Command
Target version:-
PHP Version:5.4 Complexity:
Has patch:No Affected Flow version:Flow 2.0.0

Description

I have the following (awesome) command:

<?php
namespace Acme\Demo\Command;

use TYPO3\Flow\Annotations as Flow;

/**
 * TestCommand
 *
 * @Flow\Scope("singleton")
 */
class MyCommandController extends \TYPO3\Flow\Cli\CommandController {

    /**
     * @param boolean $myParam A boolean value
     * @return void
     */
    public function commandCommand($myParam) {
        echo sprintf("Result: %s\n\n", var_export($myParam, 1));
    }

}

Now, it will be called in the terminal as followed:

$ ./flow my:command --myParam FALSE
Result: bool (false)

$ ./flow my:command --myParam=FALSE
Result: bool (true)

The last command returns `TRUE` but `FALSE` is passed, because the passed value is interpreted as a string (probably because of the prefix `=`).

I'm not quite sure if it is really a bug, but it would be nice if it is interpreted as "bool (false)".


Related issues

related to TYPO3.Flow - Bug #59023: BooleanConverter should not convert empty values to boolean New 2014-05-22
duplicates TYPO3.Flow - Bug #51385: BooleanConverter considers "false" TRUE Resolved 2013-08-27

Associated revisions

Revision 8207a130
Added by Bastian Waidelich almost 2 years ago

[BUGFIX] BooleanConverter considers "false" TRUE

The BooleanConverter provided by Flow simply casts the $source
to a boolean using boxing.
With this change a string "false" (case insensitive) is considered FALSE.

Change-Id: I95ba005490fb158a17b6b7fe3dc1787d96939299
Releases: master, 2.0
Fixes: #51255
Fixes: #51385

Revision 90d745a0
Added by Bastian Waidelich over 1 year ago

[BUGFIX] BooleanConverter considers "false" TRUE

The BooleanConverter provided by Flow simply casts the $source
to a boolean using boxing.
With this change a string "false" (case insensitive) is considered FALSE.

Change-Id: I95ba005490fb158a17b6b7fe3dc1787d96939299
Releases: master, 2.0
Fixes: #51255
Fixes: #51385

History

#1 Updated by Bastian Waidelich almost 2 years ago

  • Status changed from New to Needs Feedback

just set the default to FALSE like:

1    /**
2     * @param boolean $myParam A boolean value
3     * @return void
4     */
5    public function commandCommand($myParam = FALSE) {
6        $this->outputLine("Result: %s\n\n", array($myParam));
7    }

...and omit the flag "--my-param" if you don't want to set it

#2 Updated by Timo Dödtmann almost 2 years ago

Thanks for your feedback.

I know how to correctly sends a FALSE to the CommandController.
But I think it would be nice if `--myParam=FALSE` and `--myParam FALSE` would lead to the same result.

By the way, declaration of a default value doesn't fix the different treatment of the parameter.

#3 Updated by Bastian Waidelich almost 2 years ago

Timo Dödtmann wrote:

But I think it would be nice if `--myParam=FALSE` and `--myParam FALSE` would lead to the same result.

Reading the issue again, the current behavior is exactly how it's documented at http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/CommandLine.html#passing-arguments

--foo=bar is not supported currently. So this would be a feature request and is not related to boolean arguments if I got it right!?

By the way, declaration of a default value doesn't fix the different treatment of the parameter.

That was just an example of how to turn the argument into an option that is false by default, meaning: If you omit the flag, it's FALSE if you add --flag it is TRUE

#4 Updated by Timo Dödtmann almost 2 years ago

Exactly!
--myParam FALSE works fine
--myParam=FALSE is a feature request (because FALSE is interpreted as a string)

#5 Updated by Bastian Waidelich almost 2 years ago

  • Subject changed from CommandController: Parsing of boolean values to CommandController: Fix parsing of boolean values
  • Status changed from Needs Feedback to Accepted
  • Assigned To set to Bastian Waidelich

Ok, I'm with you now. this is indeed a bug with the BooleanConverter. See #51385

#6 Updated by Gerrit Code Review almost 2 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

#7 Updated by Gerrit Code Review almost 2 years ago

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

#8 Updated by Bastian Waidelich almost 2 years ago

  • Status changed from Under Review to Closed

Closing as duplicate of #51385

#9 Updated by Gerrit Code Review over 1 year ago

  • Status changed from Closed 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

#10 Updated by Bastian Waidelich about 1 year ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF