Skip to content

WorkoutBuilder.validateSeconds accepts invalid inputs when initial parse fails (missing early return) #1289

@moeidabbasi

Description

@moeidabbasi

Description

WorkoutBuilder.validateSeconds can return true for invalid or negative time strings because it doesn't check for a failed parse (-1 sentinel).

File / Code

File: app/src/main/org/runnerup/workout/WorkoutBuilder.java

public static boolean validateSeconds(String newValue) {
  long seconds = SafeParse.parseSeconds(newValue, -1);
  long seconds2 = SafeParse.parseSeconds(DateUtils.formatElapsedTime(seconds), -1);
  return seconds == seconds2;
}

Steps to Reproduce

  1. Call WorkoutBuilder.validateSeconds("abc") or another invalid string.
  2. Observe that the method returns true even though parsing fails.

Expected Behavior

Invalid or negative inputs should immediately return false.

Actual Behavior

The method formats and re-parses the invalid input, returning true.

Impact

Leads to false validation results, which could affect time-based workout configurations.

Proposed Fix

Add a guard clause before formatting and comparison:

if (seconds < 0) return false;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions