Skip to content

[9.x] Allow any kind of whitespace in cron expressions#44110

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
onlime:cron-expression-spacing
Sep 13, 2022
Merged

[9.x] Allow any kind of whitespace in cron expressions#44110
taylorotwell merged 4 commits into
laravel:9.xfrom
onlime:cron-expression-spacing

Conversation

@onlime

@onlime onlime commented Sep 13, 2022

Copy link
Copy Markdown
Contributor

Be more tolerant on task scheduling cron expression spacing, allowing any whitespace as separator. Previously, only a single space was allowed as separator, resulting in the following exception if e.g. a tab was used instead:

$schedule->command('foobar:sample-task')->cron('5,35 *	* * *'); // "5,35 *\t* * *"
$ pa schedule:list

   ErrorException 

  Undefined array key 4

  at vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleListCommand.php:165
    161▕     {
    162▕         $expressions = explode(' ', $expression);
    163▕ 
    164▕         return collect($spacing)
  ➜ 165▕             ->map(fn ($length, $index) => str_pad($expressions[$index], $length))
    166▕             ->implode(' ');
    167▕     }
    168▕ 
    169▕     /**

@jbrooksuk jbrooksuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to man crontab

The fields may be separated by spaces or tabs.

@taylorotwell taylorotwell merged commit 43948d0 into laravel:9.x Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants