Skip to content

Commit f2ae30a

Browse files
Copilotmrjf
andauthored
fix(to_timedelta): replace exec loop with matchAll to avoid shared global regex state
Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/29d9c670-7033-40c6-baa5-3f651bf0be32 Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 7879783 commit f2ae30a

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

src/stats/to_timedelta.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,14 @@ function parseIso(m: RegExpExecArray): Timedelta | null {
369369

370370
/** Parse human-readable form: "1h 30m 20s 500ms". Returns null if nothing matched. */
371371
function parseHuman(value: string): Timedelta | null {
372-
RE_HUMAN_UNIT.lastIndex = 0; // reset global regex
373372
let totalMs = 0;
374373
let matched = false;
375374

376-
let match = RE_HUMAN_UNIT.exec(value);
377-
while (match !== null) {
375+
for (const match of value.matchAll(RE_HUMAN_UNIT)) {
378376
matched = true;
379377
const qty = Number(match[1]);
380378
const unit = (match[2] ?? "").toLowerCase();
381379
totalMs += humanUnitToMs(qty, unit);
382-
match = RE_HUMAN_UNIT.exec(value);
383380
}
384381

385382
return matched ? new Timedelta(totalMs) : null;

0 commit comments

Comments
 (0)