Skip to content

Commit daecadc

Browse files
committed
more generic fix
1 parent b474c7a commit daecadc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Rules/Regexp/RegularExpressionPatternRule.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use function in_array;
1515
use function sprintf;
1616
use function str_starts_with;
17-
use function stripos;
1817
use function strlen;
1918
use function strpos;
2019
use function strtolower;
@@ -128,18 +127,18 @@ private function validatePattern(string $pattern): ?string
128127
try {
129128
Strings::match('', $pattern);
130129
} catch (RegexpException $e) {
131-
if (
132-
stripos($e->getMessage(), 'Compilation failed') !== false
133-
&& stripos($e->getMessage(), 'UTF-8') !== false
134-
) {
135-
$patternPos = strpos($e->getMessage(), 'pattern:');
130+
$invalidPatternMessage = $e->getMessage();
131+
try {
132+
Strings::match($invalidPatternMessage, '//u');
133+
return $invalidPatternMessage;
134+
} catch (RegexpException) {
135+
$patternPos = strpos($invalidPatternMessage, 'pattern:');
136136
if ($patternPos === false) {
137137
throw new ShouldNotHappenException();
138138
}
139139
// strip invalid utf-8 pattern contents to keep the error message NEON parsable.
140-
return substr($e->getMessage(), 0, $patternPos + strlen('pattern:') - 1);
140+
return substr($invalidPatternMessage, 0, $patternPos + strlen('pattern:') - 1);
141141
}
142-
return $e->getMessage();
143142
}
144143

145144
return null;

0 commit comments

Comments
 (0)