summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPēteris Caune <cuu508@gmail.com>2021-02-26 14:17:47 +0200
committerPēteris Caune <cuu508@gmail.com>2021-02-26 14:17:47 +0200
commit670aa0c60d4bb6c876f071932aa0be16781522a2 (patch)
tree9d35345aa2cca5420a7a465a08d484b83a0543c7
parent4828a5b99ab865b44c2f57c7602f1d5496f383e5 (diff)
downloadcroniter-670aa0c60d4bb6c876f071932aa0be16781522a2.tar.gz
Fix _expand to reject expressions with an empty step
Example: 0-10/ * * * * Removed search_re, as it is identical to step_search_re. Tightened step_search_re: the "/{step}" component is optional, but if it *is* present, {step} must consist of one or more digits.
-rw-r--r--src/croniter/croniter.py10
-rwxr-xr-xsrc/croniter/tests/test_croniter.py1
2 files changed, 8 insertions, 3 deletions
diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py
index 986414f..28ad720 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+$')
any_int_re = re.compile(r'^\d+')
star_or_int_re = re.compile(r'^(\d+|\*)$')
@@ -554,13 +553,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 7be868d..5a6fd4c 100755
--- a/src/croniter/tests/test_croniter.py
+++ b/src/croniter/tests/test_croniter.py
@@ -288,6 +288,7 @@ class CroniterTest(base.TestCase):
self.assertRaises(ValueError, croniter, '-90 * * * *')
self.assertRaises(ValueError, croniter, 'a * * * *')
self.assertRaises(ValueError, croniter, '* * * janu-jun *')
+ self.assertRaises(ValueError, croniter, '0-10/ * * * *')
self.assertRaises(CroniterBadCronError, croniter, "0-1& * * * *", datetime.now())
def testSundayToThursdayWithAlphaConversion(self):