Skip to content

fix: use parsed integer num instead of rawNum in repeat helper loop - #128

Merged
nishantwrp merged 3 commits into
joplin:masterfrom
sh1vam31:fix/repeat-helper-use-parsed-num_#124
Sep 18, 2026
Merged

nishantwrp merged 3 commits into
joplin:masterfrom
sh1vam31:fix/repeat-helper-use-parsed-num_#124

Conversation

@sh1vam31

@sh1vam31 sh1vam31 commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #124

In src/helpers/repeat.ts, the repeat helper was using rawNum (a raw string) instead of num (the parsed integer) in the for loop condition.

After fix :
image

Problem

// Bug: rawNum is a string
for (let i = 0; i < rawNum; i++) {

@nishantwrp nishantwrp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a unit test that fails without this change as well

@alondmnt

Copy link
Copy Markdown
Collaborator

Hey @sh1vam31, just a friendly reminder on the requested test: a case where the input is a non-numeric string (e.g., "abc") should suffice, since that's where rawNum and num diverge.

Adds the regression test requested in review. Both cases fail against
the unfixed helper and pass with it.

parseInt and the loop's own coercion disagree on anything that is not a
clean integer string:

- "3abc": parseInt gives 3, Number gives NaN, so comparing against the
  raw string ran zero iterations and produced nothing at all
- "3.7": parseInt gives 3, Number gives 3.7, so the raw comparison ran
  one iteration too many

Note that "abc" cannot cover this, which was suggested earlier in the
review thread. parseInt returns NaN for it, so the helper throws before
reaching the loop and never exercises the difference. That path is
already covered by the existing "should throw on non-numeric input".
@alondmnt

Copy link
Copy Markdown
Collaborator

@sh1vam31 I've pushed the requested test to your branch, plus a merge of master since your branch predated the helper test file - your commit is untouched. @nishantwrp the "abc" case I suggested earlier was wrong (it throws before reaching the loop), so the test uses "3abc" and "3.7" instead, both red without the fix - could you take another look?

@sh1vam31

Copy link
Copy Markdown
Contributor Author

Thank you so much @alondmnt for adding the regression tests and merging master. The test cases with "3abc" and "3.7" explain the divergence perfectly. Looking forward to the final review from @nishantwrp.

@sh1vam31
sh1vam31 requested a review from nishantwrp September 17, 2026 05:40

@nishantwrp nishantwrp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @alondmnt and @sh1vam31!

@nishantwrp
nishantwrp merged commit 0c4934f into joplin:master Sep 18, 2026
3 checks passed
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.

repeat helper uses unparsed rawNum instead of parseInt-parsed num in loop condition

3 participants