From 7cc2574af1070d5cb1f2366b810dd888c2f596b4 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 24 Oct 2016 15:49:25 -0400 Subject: [PATCH] Improve scheduler's parameter handling (#16088) --- src/Illuminate/Console/Scheduling/Schedule.php | 10 +++++++++- tests/Console/ConsoleEventSchedulerTest.php | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 5d29012f5fdb..e36b78ef8068 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -76,7 +76,15 @@ public function exec($command, array $parameters = []) protected function compileParameters(array $parameters) { return collect($parameters)->map(function ($value, $key) { - return is_numeric($key) ? $value : $key.'='.(is_numeric($value) ? $value : ProcessUtils::escapeArgument($value)); + if (is_array($value)) { + $value = collect($value)->map(function ($value) { + return ProcessUtils::escapeArgument($value); + })->implode(' '); + } elseif (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) { + $value = ProcessUtils::escapeArgument($value); + } + + return is_numeric($key) ? $value : "{$key}={$value}"; })->implode(' '); } diff --git a/tests/Console/ConsoleEventSchedulerTest.php b/tests/Console/ConsoleEventSchedulerTest.php index 435fb811310f..6344f59921d8 100644 --- a/tests/Console/ConsoleEventSchedulerTest.php +++ b/tests/Console/ConsoleEventSchedulerTest.php @@ -22,6 +22,8 @@ public function testExecCreatesNewCommand() $schedule->exec('path/to/command', ['--foo' => 'bar']); $schedule->exec('path/to/command', ['-f', '--foo' => 'bar']); $schedule->exec('path/to/command', ['--title' => 'A "real" test']); + $schedule->exec('path/to/command', [['one', 'two']]); + $schedule->exec('path/to/command', ['-1 minute']); $events = $schedule->events(); $this->assertEquals('path/to/command', $events[0]->command); @@ -30,6 +32,8 @@ public function testExecCreatesNewCommand() $this->assertEquals("path/to/command --foo={$escape}bar{$escape}", $events[3]->command); $this->assertEquals("path/to/command -f --foo={$escape}bar{$escape}", $events[4]->command); $this->assertEquals("path/to/command --title={$escape}A {$escapeReal}real{$escapeReal} test{$escape}", $events[5]->command); + $this->assertEquals("path/to/command {$escape}one{$escape} {$escape}two{$escape}", $events[6]->command); + $this->assertEquals("path/to/command {$escape}-1 minute{$escape}", $events[7]->command); } public function testCommandCreatesNewArtisanCommand()