Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e34d994

Browse filesBrowse files
committed
bug #53516 [Console] Allow '0' as a $shortcut in InputOption.php (lawsonjl-ornl)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Console] Allow '0' as a $shortcut in InputOption.php | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #53514 | License | MIT Fixes some comparisons to no longer erroneously disallow `'0'`/`'-0'` as a shortcut value. Commits ------- 2b6fe56 [Console] Allow '0' as a $shortcut in InputOption.php
2 parents 9d45d95 + 2b6fe56 commit e34d994
Copy full SHA for e34d994

File tree

2 files changed

+17
-3
lines changed
Filter options

2 files changed

+17
-3
lines changed

‎src/Symfony/Component/Console/Input/InputOption.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/InputOption.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct(string $name, $shortcut = null, int $mode = null, st
6969
throw new InvalidArgumentException('An option name cannot be empty.');
7070
}
7171

72-
if (empty($shortcut)) {
72+
if ('' === $shortcut || [] === $shortcut) {
7373
$shortcut = null;
7474
}
7575

@@ -78,10 +78,10 @@ public function __construct(string $name, $shortcut = null, int $mode = null, st
7878
$shortcut = implode('|', $shortcut);
7979
}
8080
$shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
81-
$shortcuts = array_filter($shortcuts);
81+
$shortcuts = array_filter($shortcuts, 'strlen');
8282
$shortcut = implode('|', $shortcuts);
8383

84-
if (empty($shortcut)) {
84+
if ('' === $shortcut) {
8585
throw new InvalidArgumentException('An option shortcut cannot be empty.');
8686
}
8787
}

‎src/Symfony/Component/Console/Tests/Input/InputOptionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Input/InputOptionTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function testShortcut()
5555
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
5656
$option = new InputOption('foo');
5757
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
58+
$option = new InputOption('foo', '');
59+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty string');
60+
$option = new InputOption('foo', []);
61+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty array');
62+
$option = new InputOption('foo', ['f', '', 'fff']);
63+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
64+
$option = new InputOption('foo', 'f||fff');
65+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
66+
$option = new InputOption('foo', '0');
67+
$this->assertEquals('0', $option->getShortcut(), '-0 is an acceptable shortcut value');
68+
$option = new InputOption('foo', ['0', 'z']);
69+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in an array');
70+
$option = new InputOption('foo', '0|z');
71+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in a string-list');
5872
}
5973

6074
public function testModes()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.