Skip to content

Using Windows to report a default value that is a filename ends up with double backslash. #16420

Closed
@rquadling

Description

@rquadling

If you have ...

->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'The file', 'C:\folder\file.ext');

when you run with --help, you get ...

  -f, --file=FILE The file. [default: "C:\\folder\\file.ext"]

The double backslash is incorrect.

NOTE: The default value is coming from a .env file and the value is specific to the user using the code and they are on OSx, Unix or Windows. But, if a user types this at the command line, it will be incorrect with the double backslash.

According to https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Console/Descriptor/TextDescriptor.php#L242, outputting the JSON value rather than the literal value into the help would seem to be incorrect as it may not be appropriate in all circumstances (say the literal is NOT a filename but something else).

As TextDescriptor::formatDefaultValue() in its current form (i.e. using json_encode() rather than var_export()) was introduced to fix bug #4193, I think the consideration of showing escaped backslashes was not considered.

Now whilst escaping backslashes is normally correct (and certainly is for JSON), it really isn't appropriate for text that represents a default value that a user will type at the command line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions