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

Fixes underscore treated as wildcard in emails #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions src/Forms/MemberProfileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ public function php($data)
$isEmail = $field === 'Email';
$emailOK = !$isEmail;
if ($isEmail) {
$existing = Member::get()->filter('Email:nocase', $data['Email']);
// Case-insensitive email lookup, not using LIKE so that underscores in emails aren't treated as wildcards.
$filter = ['LOWER(Email) = LOWER(?)' => trim($data['Email'])];

// This ensures the existing member isn't the same as the current member, in case they're updating information.

if ($current = Security::getCurrentUser()) {
$existing = $existing->filter('ID:not', $current->ID);
$filter[] = ['ID <> ?' => $current->ID];
}
$emailOK = !$existing->first();

$emailOK = !DataObject::get_one(Member::class, $filter);
}
if ($other && (!$member || !$member->exists() || $other->ID != $member->ID) || !$emailOK) {
$fieldInstance = $this->form->Fields()->dataFieldByName($field);
Expand Down