File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,7 @@ public function isRegexLike(string $value): bool
43
43
44
44
$ firstCharacter = $ value [0 ];
45
45
46
- if ('\\' === $ firstCharacter ) {
47
- // This is not ideal as not true.
46
+ if (!self ::isValidDelimiter ($ firstCharacter )) {
48
47
return false ;
49
48
}
50
49
@@ -76,6 +75,13 @@ public function validateRegex(string $regex): ?string
76
75
);
77
76
}
78
77
78
+ private static function isValidDelimiter (string $ delimiter ): bool
79
+ {
80
+ // This is not ideal as not true but is good enough for our case.
81
+ // See https://github.com/humbug/php-scoper/issues/597
82
+ return '\\' !== $ delimiter && native_preg_match ('/^\p{L}$/u ' , $ delimiter ) === 0 ;
83
+ }
84
+
79
85
private static function isValidRegexFlags (string $ value ): bool
80
86
{
81
87
if ('' === $ value ) {
Original file line number Diff line number Diff line change @@ -69,11 +69,18 @@ public static function regexLikeProvider(): iterable
69
69
false ,
70
70
];
71
71
72
+ // See https://github.com/humbug/php-scoper/issues/597
72
73
yield 'fake regex (1) ' => [
73
74
'\Foo\A ' ,
74
75
false ,
75
76
];
76
77
78
+ // See https://github.com/humbug/php-scoper/issues/597
79
+ yield 'fake regex (2) ' => [
80
+ 'Bar\WB ' ,
81
+ false ,
82
+ ];
83
+
77
84
yield 'minimal fake regex ' => [
78
85
'//// ' ,
79
86
false ,
@@ -84,6 +91,16 @@ public static function regexLikeProvider(): iterable
84
91
true ,
85
92
];
86
93
94
+ yield 'regular regex with flags (1) ' => [
95
+ '~foo~iu ' ,
96
+ true ,
97
+ ];
98
+
99
+ yield 'regular regex with flags (2) ' => [
100
+ '#foo#iu ' ,
101
+ true ,
102
+ ];
103
+
87
104
yield 'regular regex with invalid flags ' => [
88
105
'/foo/NOPE ' ,
89
106
false ,
You can’t perform that action at this time.
0 commit comments