harrisiirak / cron-parser

Node.js library for parsing crontab instructions
MIT License
1.33k stars 156 forks source link

Lack of minute should not pass the validation #244

Open lvqq opened 3 years ago

lvqq commented 3 years ago

as the title, when i use expression like 20 15 * *, it pass the validation and becomes * 20 15 * * by default, i think the expression without minute should not pass the validation because minute is not optional but required.

also, the expression 20 15 * * does not pass the validation in other package or site like https://crontab.guru/

image

here is the sample, the function parseExpression should throw a error but not:

const parser = require('cron-parser');
try {
  const interval = parser.parseExpression('20 15 * *');
  interval.next();  // 2021-10-15 20:00:00
  interval.next();  // 2021-10-15 20:01:00
  interval.next();  // 2021-10-15 20:02:00
} catch(e) {
  console.log(e);
}
georgms commented 3 years ago

I've stumbled on this too. Similarly, expressions such as just 1 or 1 2 are considered valid while e.g. https://crontab.guru/ considers them invalid.

harrisiirak commented 2 years ago

Currently, validation of the input expression is rather lax, and if there isn't value specified for the field, it fills it with wildcard.

Throwing an error probably would make more sense indeed. Not sure if somebody out there is relying on this "undocumented feature", but changing it to throw an error should be rather trivial.

lvqq commented 2 years ago

Maybe it's a good idea to be part of parseExpression function option? To determine wheither there should be filled with wildcard