Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 992f765

Browse files
committed
[Console] Escape default value when dumping help
1 parent f1f5bff commit 992f765

10 files changed

+69
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public static function getInputOptions()
4343
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
4444
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
4545
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
46+
'input_option_7' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', '<comment>style</>'),
47+
'input_option_8' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('<comment>Hello</comment>', '<info>world</info>')),
4648
);
4749
}
4850

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)