diff --git a/rules/php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/slashes.php.inc b/rules/php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/slashes.php.inc new file mode 100644 index 00000000000..eae255f466c --- /dev/null +++ b/rules/php73/tests/Rector/FuncCall/RegexDashEscapeRector/Fixture/slashes.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index affc74e51fa..eddab5be3c0 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -266,9 +266,15 @@ final class BetterStandardPrinter extends Standard */ protected function pScalar_String(String_ $node): string { - $kind = $node->getAttribute(AttributeKey::KIND, String_::KIND_SINGLE_QUOTED); - if ($kind === String_::KIND_DOUBLE_QUOTED && $node->getAttribute('is_regular_pattern')) { - return '"' . $node->value . '"'; + if ($node->getAttribute('is_regular_pattern')) { + $kind = $node->getAttribute(AttributeKey::KIND, String_::KIND_SINGLE_QUOTED); + if ($kind === String_::KIND_DOUBLE_QUOTED) { + return '"' . $node->value . '"'; + } + + if ($kind === String_::KIND_SINGLE_QUOTED) { + return "'" . $node->value . "'"; + } } return parent::pScalar_String($node);