Skip to content

Commit

Permalink
Stricter repeat value validation (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisiirak authored Nov 16, 2022
1 parent 679aecd commit cac06b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ CronExpression._parseField = function _parseField (field, value, constraints) {
var repeatInterval = 1;
var atoms = val.split('/');

if (atoms.length > 2) {
throw new Error('Invalid repeat: ' + val);
}

if (atoms.length > 1) {
if (atoms[0] == +atoms[0]) {
atoms = [atoms[0] + '-' + constraints.max, atoms[1]];
Expand Down
8 changes: 8 additions & 0 deletions test/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ test('invalid expression which has repeat negative number times', function(t) {
t.end();
});

test('invalid expression which has multiple combined repeat cycles', function(t) {
t.throws(function() {
CronExpression.parse('0 5/5/5 * * *');
}, new Error('Invalid repeat: 5/5/5'));

t.end();
});

test('range test with value and repeat (second)', function(t) {
var options = {
currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
Expand Down

0 comments on commit cac06b9

Please sign in to comment.