Content-Length: 313836 | pFad | http://github.com/symfony/symfony/pull/61143

0C [Scheduler] Add validation for comma-separated weekdays in PeriodicalTrigger by wazum · Pull Request #61143 · symfony/symfony · GitHub
Skip to content

[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from

Conversation

wazum
Copy link
Contributor

@wazum wazum commented Jul 17, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60745
License MIT

Issue

When using RecurringMessage::every() with comma-separated weekdays like "Monday, Thursday, Saturday", the scheduler silently fails because PHP's DateInterval::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

  • Added comma detection check in PeriodicalTrigger::__construct()
  • Added test case in PeriodicalTriggerTest::getInvalidIntervals()
  • Clear error message guides users to use cron expressions for multiple weekdays

Alternative: For multiple weekdays, use RecurringMessage::cron('5 12 * * 1,4,6', $message, 'Europe/Warsaw') instead.

Documentation

Update is here: symfony/symfony-docs#21212

@wazum wazum requested a review from kbond as a code owner July 17, 2025 07:28
@carsonbot carsonbot added this to the 6.4 milestone Jul 17, 2025
@@ -51,6 +51,10 @@ public function __construct(

$i = $interval;
if (\is_string($interval)) {
if (str_contains($interval, ',')) {
Copy link
Member

@nicolas-grekas nicolas-grekas Jul 17, 2025

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;
     }

Copy link
Contributor Author

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.

@carsonbot carsonbot changed the title Add validation for comma-separated weekdays in PeriodicalTrigger [Scheduler] Add validation for comma-separated weekdays in PeriodicalTrigger Jul 17, 2025
@symfony symfony deleted a comment from carsonbot Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/pull/61143

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy