Skip to content
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

[Console] Better error handling when misuse of ArgvInput with arrays #54576

Merged
merged 1 commit into from
Jun 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public function __construct(?array $argv = null, ?InputDefinition $definition =
{
$argv ??= $_SERVER['argv'] ?? [];

foreach ($argv as $arg) {
if (!\is_scalar($arg) && !$arg instanceof \Stringable) {
throw new RuntimeException(sprintf('Argument values expected to be all scalars, got "%s".', get_debug_type($arg)));
}
}

// strip the application name
array_shift($argv);

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public static function provideInvalidInput(): array
new InputDefinition([new InputArgument('name', InputArgument::REQUIRED)]),
'Too many arguments, expected arguments "name".',
],
[
['cli.php', ['array']],
new InputDefinition(),
'Argument values expected to be all scalars, got "array".',
],
];
}

Expand Down