Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rquadling opened this issue Nov 2, 2015 · 2 comments
Labels

Comments

@rquadling
Copy link
Contributor

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.

@xabbuh xabbuh added the Console label Nov 2, 2015
@Tobion
Copy link
Contributor

Tobion commented Nov 28, 2015

I think we could just replace \\ with \ in the resulting json. It's not valid json then anymore, but that doesn't matter. The main problem then is that there is no way to distinguish 'C:\new' from 'C:'."\n".'ew' (with newline). So all those escape sequences in JSON like newline, nullbyte etc would look the same as the plain value. But for humans I guess it should be obvious what is meant in context and those escape sequences are rather uncommon.

fabpot added a commit that referenced this issue Nov 29, 2015
…cription (Tobion)

This PR was merged into the 2.3 branch.

Discussion
----------

[Console] do not encode backslashes in console default description

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16420
| License       | MIT
| Doc PR        | -

Commits
-------

873a541 [Console] do not encode backslashes in console default description
@fabpot fabpot closed this as completed Nov 29, 2015
@rquadling
Copy link
Contributor Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants