diff options
-rw-r--r-- | src/basic/calendarspec.c | 18 | ||||
-rw-r--r-- | src/test/test-calendarspec.c | 3 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 316db5c556..eef4ed5240 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -372,9 +372,6 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { for (;;) { unsigned i; - if (!first && **p == ' ') - return 0; - for (i = 0; i < ELEMENTSOF(day_nr); i++) { size_t skip; @@ -430,7 +427,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { return -EINVAL; l = day_nr[i].nr; - *p += 1; + *p += 2; /* Support ranges with "-" for backwards compatibility */ } else if (**p == '-') { @@ -438,10 +435,19 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { return -EINVAL; l = day_nr[i].nr; - } else + *p += 1; + + } else if (**p == ',') { l = -1; + *p += 1; + } + + /* Allow a trailing comma but not an open range */ + if (**p == 0 || **p == ' ') { + *p += strspn(*p, " "); + return l < 0 ? 0 : -EINVAL; + } - *p += 1; first = false; } } diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index c539d16867..93414c8508 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -143,6 +143,7 @@ int main(int argc, char* argv[]) { test_one("Wed-Wed,Wed *-1", "Wed *-*-01 00:00:00"); test_one("Wed..Wed,Wed *-1", "Wed *-*-01 00:00:00"); test_one("Wed, 17:48", "Wed *-*-* 17:48:00"); + test_one("Wednesday,", "Wed *-*-* 00:00:00"); test_one("Wed-Sat,Tue 12-10-15 1:2:3", "Tue..Sat 2012-10-15 01:02:03"); test_one("Wed..Sat,Tue 12-10-15 1:2:3", "Tue..Sat 2012-10-15 01:02:03"); test_one("*-*-7 0:0:0", "*-*-07 00:00:00"); @@ -213,6 +214,8 @@ int main(int argc, char* argv[]) { assert_se(calendar_spec_from_string("00:00:00.0..00.9", &c) < 0); assert_se(calendar_spec_from_string("2016~11-22", &c) < 0); assert_se(calendar_spec_from_string("*-*~5/5", &c) < 0); + assert_se(calendar_spec_from_string("Monday.. 12:00", &c) < 0); + assert_se(calendar_spec_from_string("Monday..", &c) < 0); test_timestamp(); test_hourly_bug_4031(); |