Skip to content

Commit f40aae6

Browse files
committed
allow first "|" and "(" to be escaped
1 parent 0a8a6b2 commit f40aae6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/Command/IgnoredRegexValidator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\Type\ObjectType;
1313
use PHPStan\Type\VerbosityLevel;
1414
use function count;
15-
use function str_contains;
1615
use function strrpos;
1716
use function substr;
1817

@@ -37,10 +36,10 @@ public function validate(string $regex): IgnoredRegexValidatorResult
3736
return new IgnoredRegexValidatorResult([], false, false);
3837
}
3938

40-
if (str_contains($regex, '||')) {
39+
if (Strings::match($regex, '~(?<!\\\\)(?:\\\\\\\\)*\|\|~')) {
4140
return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|');
4241
}
43-
if (str_contains($regex, '()')) {
42+
if (Strings::match($regex, '~(?<!\\\\)(?:\\\\\\\\)*\(\)~')) {
4443
return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)');
4544
}
4645

tests/PHPStan/Command/IgnoredRegexValidatorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,48 @@ public function dataValidate(): array
100100
false,
101101
false,
102102
],
103+
[
104+
'~(a\()~',
105+
[],
106+
false,
107+
false,
108+
],
109+
[
110+
'~b\\\()~',
111+
[],
112+
false,
113+
true,
114+
],
115+
[
116+
'~(c\\\\\()~',
117+
[],
118+
false,
119+
false,
120+
],
103121
[
104122
'~Result of || is always true.~',
105123
[],
106124
false,
107125
true,
108126
],
127+
[
128+
'~a\||~',
129+
[],
130+
false,
131+
false,
132+
],
133+
[
134+
'~b\\\||~',
135+
[],
136+
false,
137+
true,
138+
],
139+
[
140+
'~c\\\\\||~',
141+
[],
142+
false,
143+
false,
144+
],
109145
[
110146
'#Method PragmaRX\Notified\Data\Repositories\Notified::firstOrCreateByEvent() should return PragmaRX\Notified\Data\Models\Notified but returns Illuminate\Database\Eloquent\Model|null#',
111147
[],

0 commit comments

Comments
 (0)