More tests and a fix
This commit is contained in:
@@ -37,8 +37,8 @@ describe("isValidCron", () => {
|
||||
"0 1/ * * *",
|
||||
"0 ,1 * * *",
|
||||
"0 1, * * *",
|
||||
"0 -- * * *",
|
||||
"0 // * * *",
|
||||
"0 5--5 * * *",
|
||||
"0 *//5 * * *",
|
||||
"0 ,, * * *",
|
||||
"0 ** * * *",
|
||||
"0 0 * * BUN",
|
||||
@@ -49,6 +49,7 @@ describe("isValidCron", () => {
|
||||
"0 2/4-5 * * *",
|
||||
"0 2-4-6 * * *",
|
||||
"0 2/4/6 * * *",
|
||||
"0 2/4/6 * * *",
|
||||
]
|
||||
|
||||
for (const cron of invalid) {
|
||||
|
||||
@@ -67,10 +67,7 @@ function validateRange(
|
||||
if (!allowSeparators) {
|
||||
return false
|
||||
}
|
||||
// Allow separators
|
||||
return value.split(",").every((v) => {
|
||||
v && validateRange(v, range)
|
||||
})
|
||||
return value.split(",").every((v) => v && validateRange(v, range))
|
||||
}
|
||||
|
||||
if (value.includes("/")) {
|
||||
@@ -79,11 +76,12 @@ function validateRange(
|
||||
}
|
||||
|
||||
const [start, step, ...rest] = value.split("/")
|
||||
// Supports */TUE and similar, which needs to be verified with the go cron library
|
||||
const stepNumber = convertToNumber(range, step)
|
||||
if (rest.length > 0 || stepNumber <= 0 || !start || !step) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Separators are only allowed in the part before the `/`, e.g. `1-5/2`
|
||||
return (
|
||||
validateRange(start, range) && validateRange(step, range, false)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user