mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 04:19:44 +01:00
[PHP 7.3] Fix regex slash escaping
This commit is contained in:
parent
bbd968b207
commit
b30eccb246
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Php73\Tests\Rector\FuncCall\RegexDashEscapeRector\Fixture;
|
||||
|
||||
class Slashes
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
preg_match('#[\-\d]$#', 'test');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php73\Tests\Rector\FuncCall\RegexDashEscapeRector\Fixture;
|
||||
|
||||
class Slashes
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
preg_match('#[\\-\d]$#', 'test');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user