Skip to content

Commit bab9047

Browse files
deemonicclaude
andcommitted
fix: eliminate nested quantifiers in separator regex to prevent JIT stack overflow
Each branch in the separator group now matches exactly one character, with the outer {0,3}? handling repetition. Removes redundant (?:\s) alternative since \s is already in the character class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c31117c commit bab9047

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Core/Matchers/RegexMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function generateSeparatorExpression(array $separators): string
2929
{
3030
$normalSeparators = array_filter($separators, fn($sep) => $sep !== '.');
3131

32-
$pattern = $this->generateEscapedExpression($normalSeparators, self::ESCAPED_SEPARATOR_CHARACTERS);
32+
$pattern = $this->generateEscapedExpression($normalSeparators, self::ESCAPED_SEPARATOR_CHARACTERS, '');
3333

34-
return '(?:' . $pattern . '|\.(?=\w)|(?:\s)){0,3}';
34+
return '(?:' . $pattern . '|\.(?=\w)){0,3}?';
3535
}
3636

3737
public function generateSubstitutionExpressions(array $substitutions): array

0 commit comments

Comments
 (0)