bug #28863 [Process] Allow to pass non-string arguments to Process (vudaltsov)
This PR was merged into the 4.1 branch.
Discussion
----------
[Process] Allow to pass non-string arguments to Process
| Q | A
| ------------- | ---
| Branch? | 4.1
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/28609
| License | MIT
| Doc PR |
Sometimes you might pass integers, floats, nulls as command arguments to the Process constructor.
Before 4.0 and https://github.com/symfony/symfony/pull/24722 that worked fine. Now it throws because of an invalid type.
I think we can drop the type hint here safely and stringify the value implicitly in the method. That will be a little more convenient.
Commits
-------
acf8b8338a
Remove Process::escapeArgument argument type hint
This commit is contained in:
commit
d010eb3a41
|
@ -1530,14 +1530,14 @@ class Process implements \IteratorAggregate
|
|||
/**
|
||||
* Escapes a string to be used as a shell argument.
|
||||
*/
|
||||
private function escapeArgument(string $argument): string
|
||||
private function escapeArgument(?string $argument): string
|
||||
{
|
||||
if ('' === $argument || null === $argument) {
|
||||
return '""';
|
||||
}
|
||||
if ('\\' !== \DIRECTORY_SEPARATOR) {
|
||||
return "'".str_replace("'", "'\\''", $argument)."'";
|
||||
}
|
||||
if ('' === $argument = (string) $argument) {
|
||||
return '""';
|
||||
}
|
||||
if (false !== strpos($argument, "\0")) {
|
||||
$argument = str_replace("\0", '?', $argument);
|
||||
}
|
||||
|
|
Reference in New Issue