From 8671dfaf324431fc6838ae2bb099d2c6fde9fb0b Mon Sep 17 00:00:00 2001 From: GiulioSavini Date: Fri, 27 Mar 2026 11:30:47 +0100 Subject: [PATCH] fix: allow 6-field cron expressions with seconds The cron editor rejected sub-minute expressions like `*/30 * * * * *` because validation required exactly 5 fields. Now accepts both 5-field (standard) and 6-field (with seconds) cron expressions. Also fixes schedule type auto-detection to correctly fall back to 'custom' for 6-field expressions instead of misinterpreting field positions. Fixes #819 --- src/lib/components/cron-editor.svelte | 16 ++++------------ .../api/auto-update/[containerName]/+server.ts | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/lib/components/cron-editor.svelte b/src/lib/components/cron-editor.svelte index d1af258..961593d 100644 --- a/src/lib/components/cron-editor.svelte +++ b/src/lib/components/cron-editor.svelte @@ -19,7 +19,7 @@ // Detect schedule type from cron expression function detectScheduleType(cron: string): 'daily' | 'weekly' | 'custom' { const parts = cron.split(' '); - if (parts.length < 5) return 'custom'; + if (parts.length !== 5) return 'custom'; const [min, hr, day, month, dow] = parts; @@ -137,23 +137,15 @@ onchange(newValue); } - // Validate cron expression + // Validate cron expression (supports 5-field and 6-field with seconds) function isValidCron(cron: string): boolean { const parts = cron.trim().split(/\s+/); - if (parts.length !== 5) return false; - - const [min, hr, day, month, dow] = parts; + if (parts.length !== 5 && parts.length !== 6) return false; // Basic pattern validation (number, *, */n, range, list) const cronFieldPattern = /^(\*|(\*\/\d+)|\d+(-\d+)?(,\d+(-\d+)?)*)$/; - return ( - cronFieldPattern.test(min) && - cronFieldPattern.test(hr) && - cronFieldPattern.test(day) && - cronFieldPattern.test(month) && - cronFieldPattern.test(dow) - ); + return parts.every((part) => cronFieldPattern.test(part)); } // Human-readable description using cronstrue diff --git a/src/routes/api/auto-update/[containerName]/+server.ts b/src/routes/api/auto-update/[containerName]/+server.ts index 97c925e..5694ac7 100644 --- a/src/routes/api/auto-update/[containerName]/+server.ts +++ b/src/routes/api/auto-update/[containerName]/+server.ts @@ -66,7 +66,7 @@ export const POST: RequestHandler = async ({ params, url, request, cookies }) => let scheduleType: 'daily' | 'weekly' | 'custom' = 'custom'; if (cronExpression) { const parts = cronExpression.split(' '); - if (parts.length >= 5) { + if (parts.length === 5) { const [, , day, month, dow] = parts; if (dow !== '*' && day === '*' && month === '*') { scheduleType = 'weekly';