diff options
author | Mathieu Le Marec - Pasquet <kiorky@cryptelium.net> | 2021-03-02 20:02:42 +0100 |
---|---|---|
committer | Mathieu Le Marec - Pasquet <kiorky@cryptelium.net> | 2021-03-02 20:02:42 +0100 |
commit | 3bff95d5042ed30f9948fdf89534066a0469050a (patch) | |
tree | 3f083cd3618712ad822f45d7ef97b16ab45e83e6 | |
parent | 1034336e3044fb64fadf29dc396ba7431667681d (diff) | |
parent | 670aa0c60d4bb6c876f071932aa0be16781522a2 (diff) | |
download | croniter-3bff95d5042ed30f9948fdf89534066a0469050a.tar.gz |
Merge remote-tracking branch 'cuu508/reject_empty_step'
-rw-r--r-- | src/croniter/croniter.py | 10 | ||||
-rwxr-xr-x | src/croniter/tests/test_croniter.py | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py index d6f8520..13c2068 100644 --- a/src/croniter/croniter.py +++ b/src/croniter/croniter.py @@ -15,8 +15,7 @@ import natsort from future.utils import raise_from -step_search_re = re.compile(r'^([^-]+)-([^-/]+)(/(.*))?$') -search_re = re.compile(r'^([^-]+)-([^-/]+)(/(.*))?$') +step_search_re = re.compile(r'^([^-]+)-([^-/]+)(/(\d+))?$') only_int_re = re.compile(r'^\d+$') star_or_int_re = re.compile(r'^(\d+|\*)$') VALID_LEN_EXPRESSION = [5, 6] @@ -553,13 +552,18 @@ class croniter(object): raise CroniterBadCronError( "[{0}] is not acceptable".format(expr_format)) + # Before matching step_search_re, normalize "*" to "{min}-{max}". + # Example: in the minute field, "*/5" normalizes to "0-59/5" t = re.sub(r'^\*(\/.+)$', r'%d-%d\1' % ( cls.RANGES[i][0], cls.RANGES[i][1]), str(e)) - m = search_re.search(t) + m = step_search_re.search(t) if not m: + # Before matching step_search_re, + # normalize "{start}/{step}" to "{start}-{max}/{step}". + # Example: in the minute field, "10/5" normalizes to "10-59/5" t = re.sub(r'^(.+)\/(.+)$', r'\1-%d/\2' % ( cls.RANGES[i][1]), str(e)) diff --git a/src/croniter/tests/test_croniter.py b/src/croniter/tests/test_croniter.py index fd7edbc..de88be6 100755 --- a/src/croniter/tests/test_croniter.py +++ b/src/croniter/tests/test_croniter.py @@ -289,6 +289,7 @@ class CroniterTest(base.TestCase): self.assertRaises(ValueError, croniter, 'a * * * *') self.assertRaises(ValueError, croniter, '* * * janu-jun *') self.assertRaises(ValueError, croniter, '1-1_0 * * * *') + self.assertRaises(ValueError, croniter, '0-10/ * * * *') self.assertRaises(CroniterBadCronError, croniter, "0-1& * * * *", datetime.now()) def testSundayToThursdayWithAlphaConversion(self): |