Skip to content

Commit 74291c5

Browse files
committed
impl
1 parent b0ca01e commit 74291c5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Diff for: src/Type/Regex/RegexGroupParser.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function parseGroups(string $regex): ?RegexAstWalkResult
110110
RegexGroupWalkResult::createEmpty(),
111111
);
112112

113-
if (!$subjectAsGroupResult->mightContainEmptyStringLiteral()) {
113+
if (!$subjectAsGroupResult->mightContainEmptyStringLiteral() && !$this->containsEscapeK($ast)) {
114114
// we could handle numeric-string, in case we know the regex is delimited by ^ and $
115115
if ($subjectAsGroupResult->isNonFalsy()->yes()) {
116116
$astWalkResult = $astWalkResult->withSubjectBaseType(
@@ -171,6 +171,21 @@ private function updateCapturingAstAddEmptyToken(TreeNode $ast): void
171171
$ast->setChildren([$emptyAlternationAst]);
172172
}
173173

174+
private function containsEscapeK(TreeNode $ast): bool
175+
{
176+
if ($ast->getId() === 'token' && $ast->getValueToken() === 'match_point_reset') {
177+
return true;
178+
}
179+
180+
foreach ($ast->getChildren() as $child) {
181+
if ($this->containsEscapeK($child)) {
182+
return true;
183+
}
184+
}
185+
186+
return false;
187+
}
188+
174189
private function walkRegexAst(
175190
TreeNode $ast,
176191
?RegexAlternation $alternation,

0 commit comments

Comments
 (0)