10000 Merge branch '6.4' into 7.0 · symfony/console@471ebf8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 471ebf8

Browse files
Merge branch '6.4' into 7.0
* 6.4: [AssetMapper] Handle assets with non-ascii characters in dev server [Translation] Fix `TranslationNodeVisitor` with constant domain CS fix [Routing] Remove `@final` annotation from `Route` attribute [Messenger] [AMQP] Throw exception on `nack` callback [Validator] revise Latvian translations [ErrorHandler] Fix `RecursiveDirectoryIterator` exception with wrong composer autoload [HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings [Cache] Fix possible infinite loop in `CachePoolPass` grab a service from the container only if it exists [Mime] Fix undefined array key 0 when empty sender [Console] Allow '0' as a $shortcut in InputOption.php fix multi-byte code area to convert [Validator] Make it explicit when English translation differs from its resource name
2 parents e6ab42f + 3068eac commit 471ebf8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Input/InputOption.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(string $name, string|array $shortcut = null, int $mo
7575
throw new InvalidArgumentException('An option name cannot be empty.');
7676
}
7777

78-
if (empty($shortcut)) {
78+
if ('' === $shortcut || [] === $shortcut) {
7979
$shortcut = null;
8080
}
8181

@@ -84,10 +84,10 @@ public function __construct(string $name, string|array $shortcut = null, int $mo
8484
$shortcut = implode('|', $shortcut);
8585
}
8686
$shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
87-
$shortcuts = array_filter($shortcuts);
87+
$shortcuts = array_filter($shortcuts, 'strlen'); FEC7
8888
$shortcut = implode('|', $shortcuts);
8989

90-
if (empty($shortcut)) {
90+
if ('' === $shortcut) {
9191
throw new InvalidArgumentException('An option shortcut cannot be empty.');
9292
}
9393
}

Tests/Input/InputOptionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ public function testShortcut()
5959
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
6060
$option = new InputOption('foo');
6161
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
62+
$option = new InputOption('foo', '');
63+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty string');
64+
$option = new InputOption('foo', []);
65+
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty array');
66+
$option = new InputOption('foo', ['f', '', 'fff']);
67+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
68+
$option = new InputOption('foo', 'f||fff');
69+
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
70+
$option = new InputOption('foo', '0');
71+
$this->assertEquals('0', $option->getShortcut(), '-0 is an acceptable shortcut value');
72+
$option = new InputOption('foo', ['0', 'z']);
73+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in an array');
74+
$option = new InputOption('foo', '0|z');
75+
$this->assertEquals('0|z', $option->getShortcut(), '-0 is an acceptable shortcut value when embedded in a string-list');
6276
}
6377

6478
public function testModes()

0 commit comments

Comments
 (0)
0