Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [Translation] Fix `TranslationNodeVisitor` with constant domain
  [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`
  [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
  • Loading branch information
nicolas-grekas committed Jan 23, 2024
2 parents cfdaac4 + 0aff198 commit 9aa3be6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Input/InputOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(string $name, string|array $shortcut = null, int $mo
throw new InvalidArgumentException('An option name cannot be empty.');
}

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

Expand All @@ -84,10 +84,10 @@ public function __construct(string $name, string|array $shortcut = null, int $mo
$shortcut = implode('|', $shortcut);
}
$shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
$shortcuts = array_filter($shortcuts);
$shortcuts = array_filter($shortcuts, 'strlen');
$shortcut = implode('|', $shortcuts);

if (empty($shortcut)) {
if ('' === $shortcut) {
throw new InvalidArgumentException('An option shortcut cannot be empty.');
}
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/Input/InputOptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public function testShortcut()
$this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts');
$option = new InputOption('foo');
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
$option = new InputOption('foo', '');
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty string');
$option = new InputOption('foo', []);
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null when given an empty array');
$option = new InputOption('foo', ['f', '', 'fff']);
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
$option = new InputOption('foo', 'f||fff');
$this->assertEquals('f|fff', $option->getShortcut(), '__construct() removes empty shortcuts');
$option = new InputOption('foo', '0');
$this->assertEquals('0', $option->getShortcut(), '-0 is an acceptable shortcut value');
$option = new InputOption('foo', ['0', 'z']);
$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');
}

public function testModes()
Expand Down

0 comments on commit 9aa3be6

Please sign in to comment.