Skip to content

Bug: \getStaleBranches\ does not validate the \days\ parameter #9

@404-Page-Found

Description

@404-Page-Found

Description

In \src/core/git.ts:98-102:

\\ s
export async function getStaleBranches(days: number, cwd?: string): Promise<GitBranch[]> {
const branches = await getLocalBranches(cwd)
const cutoff = new Date()
cutoff.setDate(cutoff.getDate() - days)
return branches.filter((b) => b.lastCommitDate < cutoff)
}
\\

The function accepts \days: number\ but does not validate it.

Impact

  • NaN: \cutoff.getDate() - NaN\ produces \NaN, and \setDate(NaN)\ creates an Invalid Date. All \Date < InvalidDate\ comparisons return \ alse, so no branches are ever stale.
  • Negative values: The cutoff is in the future, so no branches are ever stale.
  • Zero: Every branch is immediately considered stale, potentially causing mass deletion.

Suggested Fix

Validate that \days\ is a positive integer (\days > 0 && Number.isFinite(days)) and throw or return an error for invalid input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions