Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Scheduler] Add validation for comma-separated weekdays in PeriodicalTrigger#61143
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:6.4
Are you sure you want to change the base?
Conversation
…days in PeriodicalTrigger
186da57
to1122b09
Compare@@ -51,6 +51,10 @@ public function __construct( | |||
$i = $interval; | |||
if (\is_string($interval)) { | |||
if (str_contains($interval, ',')) { |
nicolas-grekasJul 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I feel like this might be too specific.
What about this instead?
--- a/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php+++ b/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php@@ -117,6 +117,10 @@ class PeriodicalTrigger implements StatefulTriggerInterface } }+ if ($next == $run) {+ throw new InvalidArgumentException(\sprintf('Invalid interval "%s".', $this->description));+ }+ return $next; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@nicolas-grekas You are right. I don't think this can be solved at the moment.
I have been working on it for hours now, also with the PHP parser. The underlying problem lies with PHP. Commas is too specific (we would have the same problem with spaces).
I have made a pull request for the documentation, which has already been merged.
Is this a solution that is OK for this problem (via a note in the documentation)?
Developers may continue to define invalid intervals without getting an error.
Uh oh!
There was an error while loading.Please reload this page.
Issue
When using
RecurringMessage::every()
with comma-separated weekdays like"Monday, Thursday, Saturday"
, the scheduler silently fails because PHP'sDateInterval::createFromDateString()
treats commas as delimiters, not processing the list as intended.Solution
I have done a detailed analysis and searched the PHP documentation. Comma-separated weekday strings are not officially supported by PHP's DateInterval::createFromDateString() method. The PHP manual does not document this format, and testing confirms that commas act as delimiters in the date parsing engine, causing unexpected behavior.
Added validation to detect comma-separated values in PeriodicalTrigger and throw a clear InvalidArgumentException instead of allowing silent failures.
Changes
Alternative: For multiple weekdays, use
RecurringMessage::cron('5 12 * * 1,4,6', $message, 'Europe/Warsaw')
instead.Documentation
Update is here:symfony/symfony-docs#21212