Repository navigation
fix: validate() consistency and multi-asterisk expansion - #606
Merged
Merged
Conversation
convertAsterisk used String.replace with a string argument, which only replaces the first match. In a field like */2,*/3 the second token never got converted to a range and survived as literal text that no time ever matches, so those minutes silently never fired.
validate() never checked the field count and split on raw spaces, so a 7-field expression silently ignored the extra field and irregular spacing misaligned which value each error message blamed. It now reuses the same field-count check and space normalization as validateDetailed(), so the two public APIs agree on the same input.
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.
This fixes two bugs found in the pattern validation and conversion code.
Bug 1: validate() and validateDetailed() disagreed on the same input
validate() never checked the number of fields in an expression, so a 7-field
expression like
* * * * * * *silently ignored the extra field and returnedtrue, while validateDetailed() correctly rejected it with "expected 5 or 6
fields but got 7". validate() also split on raw spaces without normalizing
double/leading spaces first, so irregular spacing could misalign which value
an error message blamed.
Fix: validate() now reuses the same field-count check and space
normalization that validateDetailed() already uses, so the two public APIs
agree on the same input.
Bug 2: multiple asterisks in the same field silently never matched
The asterisk-to-range conversion used
String.replace('*', replacement),which only replaces the first match. In a field like
*/2,*/3, only thefirst token got converted to a range; the second token (
*/3) survived asliteral text that no time value ever matches, so those minutes silently
never fired.
Fix: the conversion now splits the field on commas and converts every
*/*/ntoken individually, so all of them expand into working ranges.Test plan
then implemented the fixes (TDD)
npm run buildnpm run lintnpx tsc --noEmitnpm test(100% coverage on all V8 metrics)