fix(cron): anchor regex and accept full cron syntax#1577
Open
ahmedkamalio wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
Failed lint is unrelated to the code touched in this PR |
zemzale
approved these changes
May 18, 2026
Member
zemzale
left a comment
There was a problem hiding this comment.
Looks good, just rebase the PR please, the lint issue has been fixed
1 task
The cron validator's regex lacked `^...$` anchors, so any string containing a cron-like substring (e.g. "random text @daily more text", "prefix @every 1h suffix", "x 1 2 3 4 5 y") was accepted as a valid cron expression. Anchoring alone wasn't sufficient — the original field pattern only recognised plain numeric forms and was getting away with it via substring matching. Several existing positive test cases (`?`, `L`, `MON-FRI`, `#`, multi-field expressions with year) only passed because the regex matched a numeric fragment of the input. The field pattern is now expanded to accept the documented cron alphabet (`*`, `?`, digits, letters, `,`, `/`, `-`, `#`, `L`, `W`) while still rejecting bare single letters like "x" that aren't valid in any cron dialect. Negative test cases added to lock in the new behaviour, with a note documenting remaining false positives that would require a real cron parser to reject (out-of-range values, nonsense alphabetic tokens, etc). Signed-off-by: Ahmed Kamal <ahmed@ahmedkamal.io>
67ec40a to
c31a7da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cron validator's regex lacked
^...$anchors, so any string containing a cron-like substring (e.g."random text @daily more text","prefix @every 1h suffix","x 1 2 3 4 5 y") was accepted as a valid cron expression.Anchoring alone wasn't sufficient — the original field pattern only recognized plain numeric forms and was getting away with it via substring matching. Several existing positive test cases (
?,L,MON-FRI,#, multi-field expressions with year) only passed because the regex matched a numeric fragment of the input. The field pattern is now expanded to accept the documented cron alphabet (*,?, digits, letters,,,/,-,#,L,W) while still rejecting bare single letters like "x" that aren't valid in any cron dialect.Negative test cases added to lock in the new behavior, with a note documenting remaining false positives that would require a real cron parser to reject (out-of-range values, nonsense alphabetic tokens, etc).
Fixes Or Enhances
Make sure that you've checked the boxes below before you submit PR:
@go-playground/validator-maintainers