Skip to content

Commit

Permalink
Merge pull request #5 from lobaro/feature/block-specific-dom+dow
Browse files Browse the repository at this point in the history
Throw error when DOM and DOW are set
  • Loading branch information
Kniggebrot authored Oct 22, 2024
2 parents 63f0df3 + 2f4f7fa commit 5dffe15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ccronexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,13 @@ void cron_parse_expr(const char *expression, cron_expr *target, const char **err
set_number_hits(fields[2], target->hours, 0, CRON_MAX_HOURS, error);
if (*error) goto return_res;

// Don't allow specific values for DOM and DOW at the same time
if ( ((strcmp(fields[3], "*") != 0) && (strcmp(fields[3], "?") != 0)) &&
((strcmp(fields[5], "*") != 0) && (strcmp(fields[5], "?") != 0)) ) {
*error = "Cannot set specific values for day of month AND day of week";
goto return_res;
}

to_upper(fields[5]);
days_replaced = replace_ordinals(fields[5], DAYS_ARR, CRON_DAYS_ARR_LEN);
days_replaced = check_and_replace_h(days_replaced, 5, 1, error);
Expand Down
8 changes: 7 additions & 1 deletion ccronexpr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ void test_parse() {
assert(check_same("* * * * 2 *", "* * * * Feb *"));
assert(check_same("* * * * 1 *", "* * * * 1 *"));
assert(check_same("* * * * 1 L", "* * * * 1 SUN"));
// Cannot set specific days of month AND days of week
assert(check_same("* * * * * *",
"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19-59,H 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18-59,H 0,1,2,3,4,5,6,7,8,9,10,11-23,H 1,2,3,4,5,6,7,8,9,10,11,12,13,14-31,H jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,H mon,tue,wed,thu,fri,sat,sun,H"));
"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19-59,H 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18-59,H 0,1,2,3,4,5,6,7,8,9,10,11-23,H * jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,H mon,tue,wed,thu,fri,sat,sun,H"));
//assert(check_same("0 0 15 1,16,L * *", "0 0 15 1,L,16 * *"));
//assert(check_expr_valid("0 0 15 1,16,L * *"));
//assert(check_expr_valid("0 0 15 1,L,16 * *"));
Expand Down Expand Up @@ -609,6 +610,11 @@ void test_parse() {
assert(check_expr_invalid("H H H * H(-1-8) *"));
assert(check_expr_invalid("0 0\\ 0 * * *")); // no "escaping"
assert(check_expr_invalid("0 0 \\ 0 * * *")); // no "escaping"
// Cannot set specific days of month AND days of week
assert(check_expr_invalid("0 0 0 1 * 1"));
assert(check_expr_invalid("0 0 0 H * SUN"));
assert(check_expr_invalid("0 0 0 2 * H"));
assert(check_expr_invalid("0 0 0 2W * H"));
}

void test_bits() {
Expand Down

0 comments on commit 5dffe15

Please sign in to comment.