Skip to content

Commit

Permalink
[CodingStyle] Fixes #5987 Escape content delimiter in pattern for Con…
Browse files Browse the repository at this point in the history
…sistentPregDelimiterRector
  • Loading branch information
samsonasik committed Mar 25, 2021
1 parent d266e69 commit 3133d45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector\Fixture;

class EscapeContentDelimiterInPattern
{
public function run($value)
{
preg_match('/^#(([a-f0-9]{3}){1,2})$/i', '#ffffff');
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector\Fixture;

class EscapeContentDelimiterInPattern
{
public function run($value)
{
preg_match('#^\#(([a-f0-9]{3}){1,2})$#i', '#ffffff');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ private function refactorArgument(Arg $arg): void

$string->value = Strings::replace($value, self::INNER_REGEX, function (array $match): string {
$innerPattern = $match['content'];
$innerPattern = str_replace($this->delimiter, '\\' . $this->delimiter, $innerPattern);

// change delimiter
if (strlen($innerPattern) > 2 && $innerPattern[0] === $innerPattern[strlen($innerPattern) - 1]) {
$innerPattern[0] = $this->delimiter;
Expand Down

0 comments on commit 3133d45

Please sign in to comment.