8000 feedback · symfony/symfony@a9ed6ca · GitHub
[go: up one dir, main page]

Skip to content

Commit a9ed6ca

Browse files
committed
feedback
1 parent 075f913 commit a9ed6ca

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

src/Symfony/Component/Console/Console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../Symfony/symfony/src/Symfony/Component/Console

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,39 +209,45 @@ public function unparse(array $optionNames = []): array
209209

210210
$filteredRawOptions = 0 === \count($optionNames)
211211
? $rawOptions
212-
: array_intersect_key($rawOptions, array_fill_keys($optionNames, ''),
213-
);
212+
: array_intersect_key($rawOptions, array_fill_keys($optionNames, ''));
213+
214+
$unparsedOptions = [];
214215

215-
return array_map(
216-
fn (string $optionName) => $this->unparseOption(
216+
foreach ($filteredRawOptions as $optionName => $parsedOption) {
217+
$unparsedOption = self::unparseOption(
217218
$this->definition->getOption($optionName),
218219
$optionName,
219-
$filteredRawOptions[$optionName],
220-
),
221-
array_keys($filteredRawOptions),
222-
);
220+
$parsedOption,
221+
);
222+
223+
$unparsedOptions[] = \is_array($unparsedOption) ? $unparsedOption : [$unparsedOption];
224+
}
225+
226+
return \array_merge(...$unparsedOptions);
223227
}
224228

225229
/**
226230
* @param string|bool|int|float|array<string|bool|int|float|null>|null $value
231+
*
232+
* @return string|array<string>
227233
*/
228-
private function unparseOption(
234+
private static function unparseOption(
229235
InputOption $option,
230236
string $name,
231237
array|bool|float|int|string|null $value,
232-
): string {
238+
): array|string {
233239
return match (true) {
234240
$option->isNegatable() => \sprintf('--%s%s', $value ? '' : 'no-', $name),
235241
!$option->acceptValue() => \sprintf('--%s', $name),
236-
$option->isArray() => implode('', array_map(fn ($item) => $this->unparseOptionWithValue($name, $item), $value)),
237-
default => $this->unparseOptionWithValue($name, $value),
242+
$option->isArray() => array_map(fn ($item) => self::unparseOptionWithValue($name, $item), $value),
243+
default => self::unparseOptionWithValue($name, $value),
238244
};
239245
}
240246

241-
private function unparseOptionWithValue(
247+
private static function unparseOptionWithValue(
242248
string $name,
243249
bool|float|int|string|null $value,
244250
): string {
245-
return \sprintf('--%s=%s', $name, $this->escapeToken($value));
251+
return \sprintf('--%s=%s', $name, $value);
246252
}
247253
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ public static function unparseProvider(): iterable
771771
InputOption::VALUE_REQUIRED,
772772
),
773773
['--opt=5.3'],
774-
['--opt=\'5.3\''],
774+
['--opt=5.3'],
775775
);
776776

777777
yield 'option with non string value (array of strings)' => $createSingleOptionScenario(
@@ -780,8 +780,8 @@ public static function unparseProvider(): iterable
780780
null,
781781
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
782782
),
783-
['--opt=v1', '--opt=v2', '--opt=v3'],
784-
['--opt=v1--opt=v2--opt=v3'],
783+
['--opt=v1', '--opt=v2', '--opt=v3 --opt=v4'],
784+
['--opt=v1', '--opt=v2', '--opt=v3 --opt=v4'],
785785
);
786786

787787
yield 'negatable option (positive)' => $createSingleOptionScenario(
@@ -827,22 +827,22 @@ public static function unparseProvider(): iterable
827827

828828
yield 'escape token; escaped string token' => $createEscapeOptionTokenScenario(
829829
'"foo"',
830-
escapeshellarg('"foo"'),
830+
'"foo"',
831831
);
832832

833833
yield 'escape token; escaped string token with both types of quotes' => $createEscapeOptionTokenScenario(
834834
'"o_id in(\'20\')"',
835-
escapeshellarg('"o_id in(\'20\')"'),
835+
'"o_id in(\'20\')"',
836836
);
837837

838838
yield 'escape token; string token with spaces' => $createEscapeOptionTokenScenario(
839839
'a b c d',
840-
escapeshellarg('a b c d'),
840+
'a b c d',
841841
);
842842

843843
yield 'escape token; string token with line return' => $createEscapeOptionTokenScenario(
844844
"A\nB'C",
845-
escapeshellarg("A\nB'C"),
845+
"A\nB'C",
846846
);
847847
}
848848
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public static function unparseProvider(): iterable
365365
InputOption::VALUE_REQUIRED,
366366
),
367367
['--opt' => 5.3],
368-
['--opt=\'5.3\''],
368+
['--opt=5.3'],
369369
);
370370

371371
yield 'option with non string value (array of strings)' => $createSingleOptionScenario(
@@ -375,7 +375,7 @@ public static function unparseProvider(): iterable
375375
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
376376
),
377377
['--opt' => ['v1', 'v2', 'v3']],
378-
['--opt=v1--opt=v2--opt=v3'],
378+
['--opt=v1', '--opt=v2', '--opt=v3'],
379379
);
380380

381381
yield 'negatable option (positive)' => $createSingleOptionScenario(
@@ -425,22 +425,22 @@ public static function unparseProvider(): iterable
425425

426426
yield 'escape token; escaped string token' => $createEscapeOptionTokenScenario(
427427
'"foo"',
428-
escapeshellarg('"foo"'),
428+
'"foo"',
429429
);
430430

431431
yield 'escape token; escaped string token with both types of quotes' => $createEscapeOptionTokenScenario(
432432
'"o_id in(\'20\')"',
433-
escapeshellarg('"o_id in(\'20\')"'),
433+
'"o_id in(\'20\')"',
434434
);
435435

436436
yield 'escape token; string token with spaces' => $createEscapeOptionTokenScenario(
437437
'a b c d',
438-
escapeshellarg('a b c d'),
438+
'a b c d',
439439
);
440440

441441
yield 'escape token; string token with line return' => $createEscapeOptionTokenScenario(
442442
"A\nB'C",
443-
escapeshellarg("A\nB'C"),
443+
"A\nB'C",
444444
);
445445
}
446446
}

0 commit comments

Comments
 (0)
0