Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of minute should not pass the validation #244

Open
lvqq opened this issue Sep 22, 2021 · 3 comments
Open

Lack of minute should not pass the validation #244

lvqq opened this issue Sep 22, 2021 · 3 comments

Comments

@lvqq
Copy link

lvqq commented Sep 22, 2021

  • cron-parser version: 4.0.0
  • node: 14.16.0

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
Copy link

georgms commented Oct 26, 2021

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
Copy link
Owner

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
Copy link
Author

lvqq commented Nov 27, 2021

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

MichaelLeeHobbs added a commit to MichaelLeeHobbs/cron-parser that referenced this issue Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants