You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
->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.
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.
The text was updated successfully, but these errors were encountered:
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.
…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
If you have ...
when you run with
--help
, you get ...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. usingjson_encode()
rather thanvar_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.
The text was updated successfully, but these errors were encountered: