Skip to content

Commit cac06b9

Browse files
authored
Stricter repeat value validation (#294)
1 parent 679aecd commit cac06b9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/expression.js

+4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ CronExpression._parseField = function _parseField (field, value, constraints) {
276276
var repeatInterval = 1;
277277
var atoms = val.split('/');
278278

279+
if (atoms.length > 2) {
280+
throw new Error('Invalid repeat: ' + val);
281+
}
282+
279283
if (atoms.length > 1) {
280284
if (atoms[0] == +atoms[0]) {
281285
atoms = [atoms[0] + '-' + constraints.max, atoms[1]];

test/expression.js

+8
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ test('invalid expression which has repeat negative number times', function(t) {
283283
t.end();
284284
});
285285

286+
test('invalid expression which has multiple combined repeat cycles', function(t) {
287+
t.throws(function() {
288+
CronExpression.parse('0 5/5/5 * * *');
289+
}, new Error('Invalid repeat: 5/5/5'));
290+
291+
t.end();
292+
});
293+
286294
test('range test with value and repeat (second)', function(t) {
287295
var options = {
288296
currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')

0 commit comments

Comments
 (0)