Commit 0364541
authored
fix(cron): anchor regex and accept full cron syntax (#1577)
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 #1576
## Fixes Or Enhances
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.
@go-playground/validator-maintainers
Signed-off-by: Ahmed Kamal <ahmed@ahmedkamal.io>1 parent 8eb2659 commit 0364541
2 files changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15163 | 15163 | | |
15164 | 15164 | | |
15165 | 15165 | | |
| 15166 | + | |
| 15167 | + | |
| 15168 | + | |
| 15169 | + | |
| 15170 | + | |
| 15171 | + | |
| 15172 | + | |
| 15173 | + | |
| 15174 | + | |
| 15175 | + | |
| 15176 | + | |
| 15177 | + | |
| 15178 | + | |
| 15179 | + | |
| 15180 | + | |
| 15181 | + | |
| 15182 | + | |
| 15183 | + | |
15166 | 15184 | | |
15167 | 15185 | | |
15168 | 15186 | | |
| |||
0 commit comments