joplin / joplin/plugin-templates

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

Open
#124 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
207
Forks
40
Avg merge
7d 16h
Merged PRs (30d)
2

Description

In `src/helpers/repeat.ts`, the `repeat` helper parses the user-provided count argument using `Number.parseInt(rawNum)` and stores the result in `num`. However, the subsequent `for` loop incorrectly uses the original `rawNum` (a string) in the comparison `i < rawNum` instead of the parsed integer `num`.

This works accidentally due to JavaScript's implicit type coercion in the `<` operator (string is coerced to number), but it is semantically incorrect and could lead to unexpected behavior with edge-case inputs (e.g., strings with trailing whitespace or non-numeric suffixes like `"5abc"` which `parseInt` parses as `5` but string comparison would behave differently).

**Affected file**: `src/helpers/repeat.ts`, line 12

```javascript
// Before (bug):
for (let i = 0; i < rawNum; i++) {

// After (fix):
for (let i = 0; i < num; i++) {
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.