-
Notifications
You must be signed in to change notification settings - Fork 69
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
reject invalid cron values #59
Comments
Quick thought, why don't you implement ScheduleFields like: impl ScheduleFields {
pub(crate) fn new(
seconds: Seconds,
minutes: Minutes,
hours: Hours,
days_of_month: DaysOfMonth,
months: Months,
days_of_week: DaysOfWeek,
years: Years,
) -> Result<ScheduleFields, Error> {
if !(seconds.ordinals() - Seconds::all().ordinals()).is_empty() {
return Err(Error::from(ErrorKind::Expression("Seconds out of range".to_owned())));
}
if !(minutes.ordinals() - Minutes::all().ordinals()).is_empty() {
return Err(Error::from(ErrorKind::Expression("Minutes out of range".to_owned())));
}
//...
if !(years.ordinals() - Years::all().ordinals()).is_empty() {
// Or maybe format it like this?
return Err(
Error::from(
ErrorKind::Expression(
format!("Years out of range. Invalid values: {:#?}", years.ordinals() - Years::all().ordinals())
)
)
);
}
Ok(ScheduleFields {
years,
days_of_week,
months,
days_of_month,
hours,
minutes,
seconds,
})
}
} After that it only needs to be propagated through the nom parser. This might also fix #11 Maybe also look into using something like Edit: apparently has_next doesn't exist. |
I tried to make a draft, but it seems I was mistaken. The nom parser seems to filter the values somewhere(?) I'm not sure how it really works. |
There's already code in Lines 240 to 260 in 22ea6bc
The trouble in this example's case is that the divisor of the period is out of bounds:
To address this we'd need to bounds-check the variable Line 310 in 22ea6bc
|
Without looking into it too closely, I'd expect each instance of |
I can use values greater than 59 for seconds and minutes, and greater than 24 for hours, in a cron expressions, and that gives surprising values without errors.
Example of accepted expression:
The text was updated successfully, but these errors were encountered: