From 0586c55e62c4a393bd9766fb63d1ff87da919067 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Fri, 19 Mar 2021 10:11:02 +0100 Subject: [PATCH 1/4] prevent spaces in emails so this is not the first time a customer of mine is just copy pasting stuff in emails fields and somehow, a space at the end skips validation. this update ensure there is no space before or after the email, it would probably save a lot of time for everyone to have this build in. it's probably better to fix it here rather than at form level because this also happens for csv imports etc --- src/Security/Member.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Security/Member.php b/src/Security/Member.php index ea82d185d..976417e06 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -871,6 +871,11 @@ class Member extends DataObject */ public function onBeforeWrite() { + // Prevent spaces in emails + if($this->Email) { + $this->Email = trim($this->Email); + } + // If a member with the same "unique identifier" already exists with a different ID, don't allow merging. // Note: This does not a full replacement for safeguards in the controller layer (e.g. in a registration form), // but rather a last line of defense against data inconsistencies. From 19052e6924ccbe088e617fdfe08eb5bdbb5a9efb Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 22 Mar 2021 09:02:13 +0100 Subject: [PATCH 2/4] Update src/Security/Member.php Co-authored-by: Steve Boyd --- src/Security/Member.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security/Member.php b/src/Security/Member.php index 976417e06..be5cd4ef9 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -872,7 +872,7 @@ class Member extends DataObject public function onBeforeWrite() { // Prevent spaces in emails - if($this->Email) { + if ($this->Email) { $this->Email = trim($this->Email); } From 22b2d58b5addb44b897c694001d2d475bfc62dd9 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 22 Mar 2021 09:02:18 +0100 Subject: [PATCH 3/4] Update src/Security/Member.php Co-authored-by: Steve Boyd --- src/Security/Member.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security/Member.php b/src/Security/Member.php index be5cd4ef9..aac772bb3 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -871,7 +871,7 @@ class Member extends DataObject */ public function onBeforeWrite() { - // Prevent spaces in emails + // Remove any line-break or space characters accidentally added during a copy-paste operation if ($this->Email) { $this->Email = trim($this->Email); } From fc40e0b98a4342b08c35e970a4076ae757982198 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Mon, 22 Mar 2021 09:03:43 +0100 Subject: [PATCH 4/4] Test that email is trimmed --- tests/php/Security/MemberTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/php/Security/MemberTest.php b/tests/php/Security/MemberTest.php index d6dbd4d3d..96a30041b 100644 --- a/tests/php/Security/MemberTest.php +++ b/tests/php/Security/MemberTest.php @@ -1593,4 +1593,12 @@ class MemberTest extends FunctionalTest $this->assertSame('Johnson', $member->getLastName(), 'getLastName should proxy to Surname'); } + + public function testEmailIsTrimmed() + { + $member = new Member(); + $member->Email = " trimmed@test.com\r\n"; + $member->write(); + $this->assertNotNull(Member::get()->find('Email', 'trimmed@test.com')); + } }