forked from Mirrors/Dispatcharr
Fix cron validation to support */N step notation
Updated regex to properly support step notation with asterisk (e.g., */2, */5). Now supports all common cron patterns: - * (wildcard) - */2 (every 2 units - step notation) - 5 (specific value) - 1-5 (range) - 1-5/2 (step within range) - 1,3,5 (list) - 10-20/5 (step within range) Changed regex from: /^(\*|(\d+(-\d+)?(,\d+(-\d+)?)*)(\/\d+)?)$/ To: /^(\*\/\d+|\*|\d+(-\d+)?(\/\d+)?(,\d+(-\d+)?(\/\d+)?)*)$/ The key change is adding \*\/\d+ as the first alternative to explicitly match step notation like */2, */5, */10, etc. Backend already supports this via Django Celery Beat's CrontabSchedule, which accepts standard cron syntax including step notation.
This commit is contained in:
parent
e71e6bc3d7
commit
1a350e79e0
1 changed files with 3 additions and 2 deletions
|
|
@ -151,8 +151,9 @@ function validateCronExpression(expression) {
|
|||
|
||||
const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
|
||||
|
||||
// Validate each part (allowing *, ranges, lists, steps)
|
||||
const cronPartRegex = /^(\*|(\d+(-\d+)?(,\d+(-\d+)?)*)(\/\d+)?)$/;
|
||||
// Validate each part (allowing *, */N steps, ranges, lists, steps)
|
||||
// Supports: *, */2, 5, 1-5, 1-5/2, 1,3,5, etc.
|
||||
const cronPartRegex = /^(\*\/\d+|\*|\d+(-\d+)?(\/\d+)?(,\d+(-\d+)?(\/\d+)?)*)$/;
|
||||
|
||||
if (!cronPartRegex.test(minute)) {
|
||||
return { valid: false, error: 'Invalid minute field (0-59, *, or cron syntax)' };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue