From eae84ce372505ab6497b292d8f6aa5c37091be41 Mon Sep 17 00:00:00 2001 From: andrei-gafton-rtgt <61140282+andrei-gafton-rtgt@users.noreply.github.com> Date: Mon, 9 Mar 2020 17:10:23 +0200 Subject: [PATCH 1/3] add preg_quote to value checks in get Count for Unique validation with regex --- src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php b/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php index a7d57a89b..8ed85fd7f 100644 --- a/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php +++ b/src/Jenssegers/Mongodb/Validation/DatabasePresenceVerifier.php @@ -16,7 +16,7 @@ class DatabasePresenceVerifier extends \Illuminate\Validation\DatabasePresenceVe */ public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = []) { - $query = $this->table($collection)->where($column, 'regex', "/$value/i"); + $query = $this->table($collection)->where($column, 'regex', "/" . preg_quote($value) . "/i"); if ($excludeId !== null && $excludeId != 'NULL') { $query->where($idColumn ?: 'id', '<>', $excludeId); From dc7b6c9ad56b11fc554ec2b3276c337415023922 Mon Sep 17 00:00:00 2001 From: andrei-gafton-rtgt <61140282+andrei-gafton-rtgt@users.noreply.github.com> Date: Wed, 11 Mar 2020 08:02:30 +0200 Subject: [PATCH 2/3] add additional Test Cases --- tests/ValidationTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 638398866..a31317bcf 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -41,6 +41,26 @@ public function testUnique(): void ['name' => 'required|unique:users'] ); $this->assertFalse($validator->fails()); + + User::create(['name' => 'Johnny Cash', 'email' => 'johnny.cash+200@gmail.com']); + + $validator = Validator::make( + ['email' => 'johnny.cash+200@gmail.com'], + ['email' => 'required|unique:users'] + ); + $this->assertTrue($validator->fails()); + + $validator = Validator::make( + ['email' => 'johnny.cash+20@gmail.com'], + ['email' => 'required|unique:users'] + ); + $this->assertFalse($validator->fails()); + + $validator = Validator::make( + ['email' => 'johnny.cash+1@gmail.com'], + ['email' => 'required|unique:users'] + ); + $this->assertFalse($validator->fails()); } public function testExists(): void From 150b5ecbbe3cc89775864e65d58090f39941d306 Mon Sep 17 00:00:00 2001 From: andrei-gafton-rtgt <61140282+andrei-gafton-rtgt@users.noreply.github.com> Date: Wed, 11 Mar 2020 08:04:42 +0200 Subject: [PATCH 3/3] add email property to User --- tests/models/User.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/models/User.php b/tests/models/User.php index 1217af762..1f40ba367 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -13,6 +13,7 @@ * Class User * @property string $_id * @property string $name + * @property string $email * @property string $title * @property int $age * @property \Carbon\Carbon $birthday