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

[Console] InputOption shortcut "-0" is not allowed #53514

Copy link
Copy link
Closed
@lawsonjl-ornl

Description

@lawsonjl-ornl
Issue body actions

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

#53516

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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