diff --git a/packages/Php73/src/Rector/FuncCall/RegexDashEscapeRector.php b/packages/Php73/src/Rector/FuncCall/RegexDashEscapeRector.php index 74b28b91a693..4e9d6a225824 100644 --- a/packages/Php73/src/Rector/FuncCall/RegexDashEscapeRector.php +++ b/packages/Php73/src/Rector/FuncCall/RegexDashEscapeRector.php @@ -24,13 +24,13 @@ final class RegexDashEscapeRector extends AbstractRector /** * @var string */ - private const LEFT_HAND_UNESCAPED_DASH_PATTERN = '#(\\\\(w|s|d))-(?!\])#i'; + private const LEFT_HAND_UNESCAPED_DASH_PATTERN = '#(\[.*?\\\\(w|s|d))-(?!\])#i'; /** * @var string * @see https://regex101.com/r/TBVme9/1 */ - private const RIGHT_HAND_UNESCAPED_DASH_PATTERN = '#(?value = Strings::replace($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_PATTERN, '\-$2'); + $stringNode->value = Strings::replace($stringValue, self::RIGHT_HAND_UNESCAPED_DASH_PATTERN, '\-$1]'); // helped needed to skip re-escaping regular expression $stringNode->setAttribute('is_regular_pattern', true); } diff --git a/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/false_positive.php.inc b/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/false_positive.php.inc new file mode 100644 index 000000000000..c2a4f6b31314 --- /dev/null +++ b/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/false_positive.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/RegexDashEscapeRectorTest.php b/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/RegexDashEscapeRectorTest.php index a32c858aa6eb..ce5f079874d1 100644 --- a/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/RegexDashEscapeRectorTest.php +++ b/packages/Php73/tests/Rector/FuncCall/RegexDashEscapeRector/RegexDashEscapeRectorTest.php @@ -26,6 +26,7 @@ public function provideDataForTest(): Iterator yield [__DIR__ . '/Fixture/external_const.php.inc']; yield [__DIR__ . '/Fixture/variable.php.inc']; yield [__DIR__ . '/Fixture/multiple_variables.php.inc']; + yield [__DIR__ . '/Fixture/false_positive.php.inc']; } protected function getRectorClass(): string