jmettraux/rufus-scheduler — pull request #38 by pazustep (2012-10-10 20:24:52+00:00)
Title: Reject invalid weekday expressions

We're using CronLine.new(expr) as a quick (maybe dirty) way to validate cron expressions entered by our users. For the expression "0 17 * * MON_FRI" the constructor returns a valid object, but calling next_time on it will block forever.

This pull requests prevents this bug by rejecting the invalid expression in the first place. Now weekday expressions must match a strict regex to be considered valid: ^0*[0-7](-0*[0-7])?$ (i.e., digits 0 to 7, with optional leading zeroes, and optional range). The matching is done after replacing weekday names with numbers.