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] ArgvInput::hasParameterOption confused by short options with values #25825

Copy link
Copy link
Closed
@greg-1-anderson

Description

@greg-1-anderson
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? yes
Symfony version 3.4.2 (and others)

#24987 introduced a bug in hasParameterOption. If a short option has a value, then hasParameterOption will search the value for additional short options.

#25487 submitted a fix for this bug, but the fix appears to be incorrect.

The current implementation of parseShortOption is as follows:

    /**
     * Parses a short option.
     *
     * @param string $token The current token
     */
    private function parseShortOption($token)
    {
        $name = substr($token, 1);

        if (strlen($name) > 1) {
            if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
                // an option with a value (with no space)
                $this->addShortOption($name[0], substr($name, 1));
            } else {
                $this->parseShortOptionSet($name);
            }
        } else {
            $this->addShortOption($name, null);
        }
    }

In particular, note the substr($name, 1). If there is a short option -e that takes a value, then -etest will provide the value test to the -e option. See also the implementation of parseShortOptionSet, which has similar logic. No = is assumed or accounted for.

#25487 fixed the bug of #24987 by assuming that the value of a short option was formatted as -e=test; however, this is inconsistent with the implementation of the parsing functions.

My testing seems to uphold these observations, but please LMK if I have made an error somewhere. I'm not sure if there is a better solution than reverting #24987.

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.