Skip to content

fix(cron): accept day-of-week 7 as a valid Sunday alias#470

Open
gaoflow wants to merge 1 commit into
python-validators:masterfrom
gaoflow:fix-cron-dow-7-sunday-alias
Open

fix(cron): accept day-of-week 7 as a valid Sunday alias#470
gaoflow wants to merge 1 commit into
python-validators:masterfrom
gaoflow:fix-cron-dow-7-sunday-alias

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 24, 2026

Copy link
Copy Markdown

Bug

validators.cron() rejects valid cron expressions that use 7 for the day-of-week field. 7 is a well-documented alias for Sunday (the same as 0), supported by all major cron implementations (vixie-cron, cronie, fcron, and crontab(5)).

from validators import cron

cron('* * * * 7')    # ValidationError (incorrect — DOW 7 = Sunday)
cron('0 0 * * 0-7')  # ValidationError (incorrect — range ending at Sunday)
cron('0 0 * * 0,7')  # ValidationError (incorrect — Sunday listed twice)

Root cause

In src/validators/cron.py, the weekdays component is validated with max_val=6:

if not _validate_cron_component(weekdays, 0, 6):  # ← should be 7
    return False

Fix

Change the upper bound from 6 to 7. DOW 8 continues to be rejected (the existing test for '0 12 * * 8' still passes).

Tests

Three new cases added to test_returns_true_on_valid_cron:

  • "0 12 * * 7" — DOW=7 is Sunday
  • "0 0 * * 0-7" — range 0–7 (Sunday to Sunday)
  • "0 0 * * 0,7" — Sunday listed via both aliases

All 29 cron tests pass; the 17 pre-existing ETH address failures are unrelated.

Standard cron syntax allows weekday values 0–7, where both 0 and 7
mean Sunday (documented in crontab(5) and implemented by vixie-cron,
cronie, fcron, and most Unix cron daemons). The validator was
enforcing a max of 6, rejecting valid expressions like
`* * * * 7`, `0 0 * * 0-7`, and `0 0 * * 0,7`.

Change the weekday upper bound from 6 to 7 and add three test cases
that were previously (incorrectly) rejected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant