Closed
Description
Symfony version(s) affected
2.1-7.1
Description
In the constructor of Symfony\Component\Console\Input\InputOption
there is some code to check for empty values of $shortcut
:
if (empty($shortcut)) {
$shortcut = null;
}
if (null !== $shortcut) {
if (\is_array($shortcut)) {
$shortcut = implode('|', $shortcut);
}
$shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
$shortcuts = array_filter($shortcuts);
$shortcut = implode('|', $shortcuts);
if (empty($shortcut)) {
throw new InvalidArgumentException('An option shortcut cannot be empty.');
}
}
Presumably the goal is to disallow empty strings as shortcut values.
But the use of array_filter
with the default/empty callback here prevents using a shortcut like -0
, because '0'
evaluates to false
. (While uncommon, -0
might be used in a command-line application to enable null-terminated output - see for example xargs or locate)
How to reproduce
Configure the following input option on any console command:
new InputOption('null-terminated', '0', description: 'Print null-terminated output')
Observe the exception when executing the command:
An option shortcut cannot be empty.
Possible Solution
Additional Context
No response