Skip to content

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

@Jitmisra

Description

@Jitmisra

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions