Skip to content

Commit

Permalink
dev/mail/15 move santize to function and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmcandrew committed Jul 2, 2018
1 parent c65ce89 commit ccbfdc7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CRM/Admin/Form/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ public function postProcess() {

//make sure we only have a single space, CRM-6977 and dev/mail/15
if ($this->_gName == 'from_email_address') {
preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $params['label'], $parts);
$params['label'] = "\"{$parts[1]}\" <$parts[2]>";
$params['label'] = $this->sanitizeFromEmailAddress($params['label']);
}
}

Expand Down Expand Up @@ -509,4 +508,9 @@ public function postProcess() {
}
}

public function sanitizeFromEmailAddress($email) {
preg_match("/^\"(.*)\" *<([^@>]*@[^@>]*)>$/", $email, $parts);
return "\"{$parts[1]}\" <$parts[2]>";
}

}
18 changes: 18 additions & 0 deletions tests/phpunit/CRM/Core/OptionGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,22 @@ public function testsOptionGroupDataType($optionGroup, $expectedDataType) {
}
}


public function emailAddressTests() {
$tests[] = array('"Name"<email@example.com>', '"Name" <email@example.com>');
$tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
$tests[] = array('"Name" <email@example.com>', '"Name" <email@example.com>');
return $tests;
}


/**
* @dataProvider emailAddressTests
*/
public function testSanitizeFromEmailAddress($dirty, $clean) {
$form = new CRM_Admin_Form_Options();
$actual = $form->sanitizeFromEmailAddress($dirty);
$this->assertEquals($actual, $clean);
}

}

0 comments on commit ccbfdc7

Please sign in to comment.