10000 [Console] Escape default value when dumping help by lyrixx · Pull Request #21078 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Escape default value when dumping help #21078

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

Merged
merged 1 commit into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
Expand Down Expand Up @@ -236,6 +237,16 @@ private function writeText($content, array $options = array())
*/
private function formatDefaultValue($default)
{
if (is_string($default)) {
$default = OutputFormatter::escape($default);
} elseif (is_array($default)) {
foreach ($default 10000 as $key => $value) {
if (is_string($value)) {
$default[$key] = OutputFormatter::escape($value);
}
}
}

if (PHP_VERSION_ID < 50400) {
return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static function getInputArguments()
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
'input_argument_with_style' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', '<comment>style</>'),
);
}

Expand All @@ -43,6 +44,8 @@ public static function getInputOptions()
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
'input_option_with_style' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', '<comment>style</>'),
'input_option_with_style_array' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('<comment>Hello</comment>', '<info>world</info>')),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "argument_name",
"is_required": false,
"is_array": false,
"description": "argument description",
"default": "<comment>style</>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**argument_name:**

* Name: argument_name
* Is required: no
* Is array: no
* Description: argument description
* Default: `'<comment>style</>'`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<info>argument_name</info> argument description<comment> [default: "\<comment>style\</>"]</comment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="0" is_array="0">
<description>argument description</description>
<defaults>
<default>&lt;comment&gt;style&lt;/&gt;</default>
</defaults>
</argument>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "--option_name",
"shortcut": "-o",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
"description": "option description",
"default": "<comment>style</>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**option_name:**

* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: option description
* Default: `'<comment>style</>'`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: "\<comment>style\</>"]</comment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
<description>option description</description>
<defaults>
<default>&lt;comment&gt;style&lt;/&gt;</default>
</defaults>
</option>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "--option_name",
"shortcut": "-o",
"accept_value": true,
"is_value_required": true,
"is_multiple": true,
"description": "option description",
"default": [
"<comment>Hello</comment>",
"<info>world</info>"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**option_name:**

* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: yes
* Is multiple: yes
* Description: option description
* Default: `array ( 0 => '<comment>Hello</comment>', 1 => '<info>world</info>',)`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: ["\<comment>Hello\</comment>","\<info>world\</info>"]]</comment><comment> (multiple values allowed)</comment>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="1">
<description>option description</description>
<defaults>
<default>&lt;comment&gt;Hello&lt;/comment&gt;</default>
<default>&lt;info&gt;world&lt;/info&gt;</default>
</defaults>
</option>
0