Skip to content

Commit 99447c0

Browse files
authored
Merge pull request #146 from membrane-php/fix-regex-to-php
Fixes converting a regex validator to php code when special chars are…
2 parents f82511e + 1c92791 commit 99447c0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Validator/String/Regex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __toString(): string
2222

2323
public function __toPHP(): string
2424
{
25-
return sprintf('new %s(\'%s\')', self::class, addslashes($this->pattern));
25+
return sprintf('new %s(\'%s\')', self::class, addcslashes($this->pattern, "\\\'"));
2626
}
2727

2828
public function validate(mixed $value): Result

tests/Validator/String/RegexTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function toStringTest(): void
3535
#[DataProvider('provideRegularExpresions')]
3636
public function toPHPTest(string $regex): void
3737
{
38-
$sut = new Regex('/[abc]/i');
38+
$sut = new Regex($regex);
3939

4040
$actual = $sut->__toPHP();
4141

0 commit comments

Comments
 (0)