Skip to content

Commit

Permalink
[Console] Allow false as a $shortcut in InputOption
Browse files Browse the repository at this point in the history
  • Loading branch information
jayminsilicon authored and nicolas-grekas committed Feb 1, 2024
1 parent e111a54 commit 2025baa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/InputOption.php
Expand Up @@ -69,7 +69,7 @@ public function __construct(string $name, $shortcut = null, ?int $mode = null, s
throw new InvalidArgumentException('An option name cannot be empty.');
}

if ('' === $shortcut || [] === $shortcut) {
if ('' === $shortcut || [] === $shortcut || false === $shortcut) {
$shortcut = null;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/InputOptionTest.php
Expand Up @@ -69,6 +69,8 @@ public function testShortcut()
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in an array');
$option = new InputOption('foo', '0|z');
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in a string-list');
$option = new InputOption('foo', false);
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given a false as value');
}

public function testModes()
Expand Down

0 comments on commit 2025baa

Please sign in to comment.