File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments