Skip to content

Commit

Permalink
Improve scheduler's parameter handling (#16088)
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro authored and taylorotwell committed Oct 24, 2016
1 parent f0cf6fa commit 7cc2574
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Console/ConsoleEventSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down

0 comments on commit 7cc2574

Please sign in to comment.