8000 bug #21078 [Console] Escape default value when dumping help (lyrixx) · symfony/symfony@6faa8ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 6faa8ab

Browse files
bug #21078 [Console] Escape default value when dumping help (lyrixx)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Escape default value when dumping help | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- c242690 [Console] Escape default value when dumping help
2 parents 7e8e9e3 + c242690 commit 6faa8ab

14 files changed

+92
-0
lines changed

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Formatter\OutputFormatter;
1617
use Symfony\Component\Console\Helper\Helper;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputDefinition;
@@ -236,6 +237,16 @@ private function writeText($content, array $options = array())
236237
*/
237238
private function formatDefaultValue($default)
238239
{
240+
if (is_string($default)) {
241+
$default = OutputFormatter::escape($default);
242+
} elseif (is_array($default)) {
243+
foreach ($default as $key => $value) {
244+
if (is_string($value)) {
245+
$default[$key] = OutputFormatter::escape($value);
246+
}
247+
}
248+
}
249+
239250
if (PHP_VERSION_ID < 50400) {
240251
return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
241252
}

src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static function getInputArguments()
3131
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
3232
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
3333
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
34+
'input_argument_with_style' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', '<comment>style</>'),
3435
);
3536
}
3637

@@ -43,6 +44,8 @@ public static function getInputOptions()
4344
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
4445
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
4546
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
47+
'input_option_with_style' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', '<comment>style</>'),
48+
'input_option_with_style_array' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('<comment>Hello</comment>', &# 8000 39;<info>world</info>')),
4649
);
4750
}
4851

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "argument_name",
3+
"is_required": false,
4+
"is_array": false,
5+
"description": "argument description",
6+
"default": "<comment>style</>"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
**argument_name:**
2+
3+
* Name: argument_name
4+
* Is required: no
5+
* Is array: no
6+
* Description: argument description
7+
* Default: `'<comment>style</>'`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<info>argument_name</info> argument description<comment> [default: "\<comment>style\</>"]</comment>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<argument name="argument_name" is_required="0" is_array="0">
3+
<description>argument description</description>
4+
<defaults>
5+
<default>&lt;comment&gt;style&lt;/&gt;</default>
6+
</defaults>
7+
</argument>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "--option_name",
3+
"shortcut": "-o",
4+
"accept_value": true,
5+
"is_value_required": true,
6+
"is_multiple": false,
7+
"description": "option description",
8+
"default": "<comment>style</>"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**option_name:**
2+
3+
* Name: `--option_name`
4+
* Shortcut: `-o`
5+
* Accept value: yes
6+
* Is value required: yes
7+
* Is multiple: no
8+
* Description: option description
9+
* Default: `'<comment>style</>'`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: "\<comment>style\</>"]</comment>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
3+
<description>option description</description>
4+
<defaults>
5+
<default>&lt;comment&gt;style&lt;/&gt;</default>
6+
</defaults>
7+
</option>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "--option_name",
3+
"shortcut": "-o",
4+
"accept_value": true,
5+
"is_value_required": true,
6+
"is_multiple": true,
7+
"description": "option description",
8+
"default": [
9+
"<comment>Hello</comment>",
10+
"<info>world</info>"
11+
]
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**option_name:**
2+
3+
* Name: `--option_name`
4+
* Shortcut: `-o`
5+
* Accept value: yes
6+
* Is value required: yes
7+
* Is multiple: yes
8+
* Description: option description
9+
* Default: `array ( 0 => '<comment>Hello</comment>', 1 => '<info>world</info>',)`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: ["\<comment>Hello\</comment>","\<info>world\</info>"]]</comment><comment> (multiple values allowed)</comment>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="1">
3+
<description>option description</description>
4+
<defaults>
5+
<default>&lt;comment&gt;Hello&lt;/comment&gt;</default>
6+
<default>&lt;info&gt;world&lt;/info&gt;</default>
7+
</defaults>
8+
</option>

0 commit comments

Comments
 (0)
0