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

We need more validation for step #478

Open
peterqiu07 opened this issue Jan 16, 2023 · 1 comment
Open

We need more validation for step #478

peterqiu07 opened this issue Jan 16, 2023 · 1 comment

Comments

@peterqiu07
Copy link

cron/parser.go

Line 313 in bc59245

if step == 0 {

There is not enough validation for step
So when we use cron expression like "0/9999 * * * * ?", it still works, but it seems like out of expectation, and more strange
Further more, what do you expect for "0/9999 0/666 * * * ?"
image

Maybe we need to use the bounds to limit range as well as start and end

@ljluestc
Copy link

// cron/parser.go

// Validate step ranges for each cron field
func validateStep(step int, min int, max int) error {
    if step == 0 {
        return fmt.Errorf("step cannot be 0")
    }
    if step < min || step > max {
        return fmt.Errorf("step %d is out of bounds, must be between %d and %d", step, min, max)
    }
    return nil
}

// The cron expression parsing logic
func parseCronExpression(expression string) error {
    // Example for validating minute field with step values
    minuteField := "0/9999"  // Example invalid value
    step := parseStep(minuteField)  // hypothetical function to parse step value from cron expression

    // Step validation for minute field (0 to 59)
    if err := validateStep(step, 0, 59); err != nil {
        return err
    }

    // Example for validating hour field with step values
    hourField := "0/666"  // Example invalid value
    step = parseStep(hourField)  // hypothetical function to parse step value from cron expression

    // Step validation for hour field (0 to 23)
    if err := validateStep(step, 0, 23); err != nil {
        return err
    }

    // Similarly for other fields (day of month, month, day of week), define their valid ranges:
    // - Day of month: 1 to 31
    // - Month: 1 to 12
    // - Day of week: 0 to 6 (Sunday to Saturday)

    return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants