Skip to content

Commit d0393f0

Browse files
authored
Fix regex detection (#596)
`\Foo\A` is detected as a regex and whilst this is true (`\` used as a delimiter here with the flag `A`), it makes a lot of things complicated for an edge case which IMO has no reasons to be: if you wish such a regex simply use another delimiter.
1 parent 40ffee4 commit d0393f0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/RegexChecker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function isRegexLike(string $value): bool
4343

4444
$firstCharacter = $value[0];
4545

46+
if ('\\' === $firstCharacter) {
47+
// This is not ideal as not true.
48+
return false;
49+
}
50+
4651
$parts = explode($firstCharacter, $value);
4752

4853
if (false === $parts || count($parts) !== 3) {

tests/RegexCheckerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,16 @@ public static function regexLikeProvider(): iterable
6464
true,
6565
];
6666

67-
yield 'fake regex' => [
67+
yield 'fake regex (0)' => [
6868
'/Foo/Bar/',
6969
false,
7070
];
7171

72+
yield 'fake regex (1)' => [
73+
'\Foo\A',
74+
false,
75+
];
76+
7277
yield 'minimal fake regex' => [
7378
'////',
7479
false,

0 commit comments

Comments
 (0)