Skip to content

Commit

Permalink
allow first "|" and "(" to be escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 11, 2024
1 parent 23d4dfa commit d08e625
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Command/IgnoredRegexValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public function validate(string $regex): IgnoredRegexValidatorResult
return new IgnoredRegexValidatorResult([], false, false);
}

if (str_contains($regex, '||')) {
if (Strings::match($regex, '~(?<!\\\\)(?:\\\\\\\\)*\|\|~')) {
return new IgnoredRegexValidatorResult([], false, true, '||', '\|\|');
}
if (str_contains($regex, '()')) {
if (Strings::match($regex, '~(?<!\\\\)(?:\\\\\\\\)*\(\)~')) {
return new IgnoredRegexValidatorResult([], false, true, '()', '\(\)');
}

Expand Down
36 changes: 36 additions & 0 deletions tests/PHPStan/Command/IgnoredRegexValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,48 @@ public function dataValidate(): array
false,
false,
],
[
'~(a\()~',
[],
false,
false,
],
[
'~b\\\()~',
[],
false,
true,
],
[
'~(c\\\\\()~',
[],
false,
false,
],
[
'~Result of || is always true.~',
[],
false,
true,
],
[
'~a\||~',
[],
false,
false,
],
[
'~b\\\||~',
[],
false,
true,
],
[
'~c\\\\\||~',
[],
false,
false,
],
[
'#Method PragmaRX\Notified\Data\Repositories\Notified::firstOrCreateByEvent() should return PragmaRX\Notified\Data\Models\Notified but returns Illuminate\Database\Eloquent\Model|null#',
[],
Expand Down

0 comments on commit d08e625

Please sign in to comment.