@@ -445,14 +445,14 @@ private function walkGroupAst(
445
445
foreach ($ children as $ child ) {
446
446
$ oldLiterals = $ onlyLiterals ;
447
447
448
- $ this ->getLiteralValue ($ child , $ oldLiterals , true , $ patternModifiers );
448
+ $ this ->getLiteralValue ($ child , $ oldLiterals , true , $ patternModifiers, true );
449
449
foreach ($ oldLiterals ?? [] as $ oldLiteral ) {
450
450
$ newLiterals [] = $ oldLiteral ;
451
451
}
452
452
}
453
453
$ onlyLiterals = $ newLiterals ;
454
454
} elseif ($ ast ->getId () === 'token ' ) {
455
- $ literalValue = $ this ->getLiteralValue ($ ast , $ onlyLiterals , !$ inClass , $ patternModifiers );
455
+ $ literalValue = $ this ->getLiteralValue ($ ast , $ onlyLiterals , !$ inClass , $ patternModifiers, false );
456
456
if ($ literalValue !== null ) {
457
457
if (Strings::match ($ literalValue , '/^\d+$/ ' ) === null ) {
458
458
$ isNumeric = TrinaryLogic::createNo ();
@@ -508,7 +508,7 @@ private function isMaybeEmptyNode(TreeNode $node, string $patternModifiers, bool
508
508
}
509
509
}
510
510
511
- $ literal = $ this ->getLiteralValue ($ node , $ onlyLiterals , false , $ patternModifiers );
511
+ $ literal = $ this ->getLiteralValue ($ node , $ onlyLiterals , false , $ patternModifiers, false );
512
512
if ($ literal !== null ) {
513
513
if ($ literal !== '' && $ literal !== '0 ' ) {
514
514
$ isNonFalsy = true ;
@@ -528,7 +528,7 @@ private function isMaybeEmptyNode(TreeNode $node, string $patternModifiers, bool
528
528
/**
529
529
* @param array<string>|null $onlyLiterals
530
530
*/
531
- private function getLiteralValue (TreeNode $ node , ?array &$ onlyLiterals , bool $ appendLiterals , string $ patternModifiers ): ?string
531
+ private function getLiteralValue (TreeNode $ node , ?array &$ onlyLiterals , bool $ appendLiterals , string $ patternModifiers, bool $ inCharacterClass ): ?string
532
532
{
533
533
if ($ node ->getId () !== 'token ' ) {
534
534
return null ;
@@ -551,15 +551,17 @@ private function getLiteralValue(TreeNode $node, ?array &$onlyLiterals, bool $ap
551
551
return null ;
552
552
}
553
553
554
+ $ isEscaped = false ;
554
555
if (strlen ($ value ) > 1 && $ value [0 ] === '\\' ) {
555
556
$ value = substr ($ value , 1 ) ?: '' ;
557
+ $ isEscaped = true ;
556
558
}
557
559
558
560
if (
559
561
$ appendLiterals
560
562
&& in_array ($ token , ['literal ' , 'range ' , 'class_ ' , '_class_literal ' ], true )
561
563
&& $ onlyLiterals !== null
562
- && !in_array ($ value , ['. ' ], true )
564
+ && ( !in_array ($ value , ['. ' ], true ) || $ isEscaped || $ inCharacterClass )
563
565
) {
564
566
if ($ onlyLiterals === []) {
565
567
$ onlyLiterals = [$ value ];
0 commit comments