Skip to content

Commit

Permalink
[Php73] Skip double escape dash on next with quantifier outside brack…
Browse files Browse the repository at this point in the history
…et on RegexDashEscapeRector (#1006)

* [Php73] Skip escape dash outside bracket on RegexDashEscapeRector

* rename fixture

* rename

* fix more quantifiers

* final touch

* add more fixture
  • Loading branch information
samsonasik committed Oct 15, 2021
1 parent 4e377b2 commit 2d6a25b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Rector\Tests\Php73\Rector\FuncCall\RegexDashEscapeRector\Fixture;

class SkipDoubleEscapeMoreQuantifiers
{
public function run(string $string)
{
preg_match('#^\-\s*[0-9]+$#', $string);
preg_match('#^\-\s+[0-9]+$#', $string);
preg_match('#^\-\s{1,10}[0-9]+$#', $string);
preg_match('#^\-\s{1,}[0-9]+$#', $string);
preg_match('#^\-\s(ab)*[0-9]+$#', $string);
preg_match('#^\-\s(ab){1,10}[0-9]+$#', $string);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Php73\Rector\FuncCall\RegexDashEscapeRector\Fixture;

class SkipDoubleEscapeNextNonQuantifier
{
public function run(string $string)
{
preg_match('#^\-\sa[0-9]+$#', $string);
}
}

?>
4 changes: 2 additions & 2 deletions rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final class RegexDashEscapeRector extends AbstractRector implements MinPhpVersio

/**
* @var string
* @see https://regex101.com/r/TBVme9/3
* @see https://regex101.com/r/TBVme9/8
*/
private const RIGHT_HAND_UNESCAPED_DASH_REGEX = '#(?<!\[)-(\\\\(w|s|d)[^\?]*?)\]#i';
private const RIGHT_HAND_UNESCAPED_DASH_REGEX = '#(?<!\[)-(\\\\(w|s|d)[.*]?)\]#i';

public function __construct(
private RegexPatternArgumentManipulator $regexPatternArgumentManipulator
Expand Down

0 comments on commit 2d6a25b

Please sign in to comment.