FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: validate() consistency and multi-asterisk expansion by merencia · Pull Request #606 · node-cron/node-cron · GitHub

fix: validate() consistency and multi-asterisk expansion - #606

Merged
merencia merged 2 commits into
mainfrom
fix/validate-consistency
Jul 2, 2026
Merged

fix: validate() consistency and multi-asterisk expansion#606
merencia merged 2 commits into
mainfrom
fix/validate-consistency

Conversation

merencia commented Jul 2, 2026

Copy link
Copy Markdown
Member

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 returned
true, 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 the
first token got converted to a range; the second token (*/3) survived as
literal 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
*/*/n token individually, so all of them expand into working ranges.

Test plan

  • Added failing tests first, confirmed they failed for the right reason,
    then implemented the fixes (TDD)
  • npm run build
  • npm run lint
  • npx tsc --noEmit
  • npm test (100% coverage on all V8 metrics)

merencia added 2 commits July 2, 2026 16:18
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.
merencia merged commit 8cf41c4 into main Jul 2, 2026
8 checks passed
merencia deleted the fix/validate-consistency branch July 2, 2026 19:38
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL