Skip to content

Commit ffc34fa

Browse files
committed
bug #40593 Uses the correct assignment action for console options depending if they are short or long (topikito)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Uses the correct assignment action for console options depending if they are short or long | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40590 | License | MIT | Doc PR | - Checks if the option is short or long, and assigns the corresponding "glue" for the assignment. Commits ------- d0a3c53 Uses the correct assignment action for console options depending if they are short or long
2 parents a863e2f + d0a3c53 commit ffc34fa

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Symfony/Component/Console/Input/ArrayInput.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ public function __toString()
108108
$params = [];
109109
foreach ($this->parameters as $param => $val) {
110110
if ($param && \is_string($param) && '-' === $param[0]) {
111+
$glue = ('-' === $param[1]) ? '=' : ' ';
111112
if (\is_array($val)) {
112113
foreach ($val as $v) {
113-
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
114+
$params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : '');
114115
}
115116
} else {
116-
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
117+
$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
117118
}
118119
} else {
119120
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);

src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ public function provideInvalidInput()
162162
public function testToString()
163163
{
164164
$input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]);
165-
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
165+
$this->assertEquals('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
166166

167167
$input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]);
168-
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
168+
$this->assertSame('-b bval_1 -b bval_2 --f=fval_1 --f=fval_2', (string) $input);
169169

170170
$input = new ArrayInput(['array_arg' => ['val_1', 'val_2']]);
171171
$this->assertSame('val_1 val_2', (string) $input);

0 commit comments

Comments
 (0)