Skip to content

Commit f41fa5d

Browse files
Copilotmrjf
andauthored
Fix string_ops_extended.ts: use matchAll() to avoid regex state issues and ReDoS
Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/59ed5e8d-fa0e-441b-a183-ff544daaf104 Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 47c10e3 commit f41fa5d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/stats/string_ops_extended.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ export function strExtractGroups(
208208

209209
/** Parse named capture group names from a regex source string. */
210210
function extractGroupNames(re: RegExp): string[] {
211-
const namedGroupPattern = /\(\?<([^>]+)>/g;
211+
// Match named capture groups: (?<name>...)
212+
// Use matchAll for safety — it creates a fresh iterator with its own state.
213+
const matches = re.source.matchAll(/\(\?<([^>]+)>/g);
212214
const names: string[] = [];
213-
let m: RegExpExecArray | null = namedGroupPattern.exec(re.source);
214-
while (m !== null) {
215+
for (const m of matches) {
215216
const name = m[1];
216217
if (name !== undefined) {
217218
names.push(name);
218219
}
219-
m = namedGroupPattern.exec(re.source);
220220
}
221221
return names;
222222
}

0 commit comments

Comments
 (0)