Skip to content

Commit

Permalink
Fix regex match
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGuilloux committed Aug 19, 2021
1 parent 350ff20 commit 934d939
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Doctrine/EventListener/SqliteRegexOnPostConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public function postConnect(ConnectionEventArgs $args): void
'REGEXP',
static function (string $regex, string $value): int {

return preg_match('/^' . $regex . '$/', $value) ?: 0;
return preg_match('/' . $regex . '/', $value) ?: 0;
}
);

$connection->sqliteCreateFunction(
'REGEXP_REPLACE',
static function (string $value, string $regex, string $replace): string {
return preg_replace('/^' . $regex . '$/', $replace, $value);
return preg_replace('/' . $regex . '/', $replace, $value);
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/SqliteRegexInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testRegex(): void
->select('de.id')
->from(DummyEntity::class, 'de')
->where('de.id < 15')
->andWhere("REGEXP(de.reference, 'number-\\d') = 1");
->andWhere("REGEXP(de.reference, 'number-\\d$') = 1");

$result = $qb->getQuery()->getResult();

Expand All @@ -36,7 +36,7 @@ public function testRegexReplace(): void
->select('de.id')
->from(DummyEntity::class, 'de')
->where('de.id < 15')
->andWhere("REGEXP_REPLACE(de.reference, 'number-\\d', 'number_1') = 'number_1'");
->andWhere("REGEXP_REPLACE(de.reference, 'number-\\d$', 'number_1') = 'number_1'");

$result = $qb->getQuery()->getResult();

Expand Down

0 comments on commit 934d939

Please sign in to comment.