Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] Backport of #1992 to 3.7 #2154

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.

### Changed
- (Backport) MongodbQueueServiceProvider does not use the DB Facade anymore [#2149](https://github.com/jenssegers/laravel-mongodb/pull/2149) by [@curosmj](https://github.com/curosmj)
- Add escape regex chars to DB Presence Verifier [#1992](https://github.com/jenssegers/laravel-mongodb/pull/1992) by [@andrei-gafton-rtgt](https://github.com/andrei-gafton-rtgt).

## [3.7.1] - 2020-10-29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down