Repository navigation
Reject malformed numbers in cron schedule fields - #458
Open
leninworld wants to merge 1 commit into
Open
leninworld wants to merge 1 commit into
leninworld wants to merge 1 commit into
Conversation
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.
Closes #309
What changed
expandFieldinbackend/src/schedules/cron.tsread each value, range end and step withNumber(), so an empty side counted as 0 and hex, exponent, sign and decimal forms were accepted.-5 * * * *was saved as minutes 0 to 5,/15 * * * *as every 15 minutes, and0x1E 9 * * *as 9:30./^\d+$/) before they are read. An empty side of a range and an empty value before/fail the same check. Valid expressions, including*,*/n,a-b/n,a/nand leading zeros like00 09 * * *, read as before.schedules/service.ts) and bot import (bots/transfer.ts) all validate throughisValidCron, so they now reject these expressions too.Testing
isValidCronbefore and after:-5 * * * *,/15 * * * *,0- * * * *,* * * * -1(empty side)0x1E 9 * * *,1e1 * * * *,*/1e1 * * * *,+5 * * * **/+5 * * * *,1.0 * * * *,1,0x2 * * * ** * * * *,*/15 * * * *,0-30/5 9-17 * * 1-5,5/10 * * * *,0 0 1,15 * *,00 09 * * *bun test --timeout 30000 ./backend/test/schedules-cron.test.ts(from the repo root): 27 pass, 0 fail. On main the extended "rejects malformed expressions" test fails (26 pass, 1 fail). It now holds the issue's eight expressions plus three sibling forms: a signed step, a decimal and a hex value inside a comma list.bunx -p typescript@5.9.3 tsc --noEmitinbackend(after installing each package's deps, as CI does) andbun test scripts/agent-docs.test.ts: pass.Not checked: I did not run the full backend suite (it needs the Postgres test database) or create a schedule in the app; the change is in the validator that those four paths call.
One effect to know: a schedule already saved with one of these expressions now reads as invalid, so the matcher no longer fires it (the same as any other invalid cron). I did not add a migration for such rows.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.