Skip to content

Commit

Permalink
FIX Trim recipient email addresses before write
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 14, 2020
1 parent 575d1f9 commit 59cd87d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions code/Model/Recipient/EmailRecipient.php
Expand Up @@ -116,6 +116,17 @@ public function requireDefaultRecords()
DB::query("UPDATE \"UserDefinedForm_EmailRecipient\" SET \"FormClass\" = 'Page' WHERE \"FormClass\" IS NULL");
}

public function onBeforeWrite()
{
parent::onBeforeWrite();

// email addresses have trim() applied to them during validation for a slightly nicer UX
// apply trim() here too before saving to the database
$this->EmailAddress = trim($this->EmailAddress);
$this->EmailFrom = trim($this->EmailFrom);
$this->EmailReplyTo = trim($this->EmailReplyTo);
}

public function summaryFields()
{
$fields = parent::summaryFields();
Expand Down
12 changes: 12 additions & 0 deletions tests/Model/Recipient/EmailRecipientTest.php
Expand Up @@ -38,4 +38,16 @@ public function testEmptyRecipientFailsValidation()
$recipient->EmailFrom = 'test@example.com';
$recipient->write();
}

public function testEmailAddressesTrimmed()
{
$recipient = new EmailRecipient();
$recipient->EmailAddress = 'test1@example.com ';
$recipient->EmailFrom = 'test2@example.com ';
$recipient->EmailReplyTo = 'test3@example.com ';
$recipient->write();
$this->assertSame('test1@example.com', $recipient->EmailAddress);
$this->assertSame('test2@example.com', $recipient->EmailFrom);
$this->assertSame('test3@example.com', $recipient->EmailReplyTo);
}
}

0 comments on commit 59cd87d

Please sign in to comment.