Add tests and fix other cases where autoLinkEmail would fail.

Refs #2403
This commit is contained in:
mark_story 2013-11-29 22:57:43 -05:00
parent 7c66d0db50
commit a9ca1bdc58
2 changed files with 23 additions and 8 deletions

View file

@ -363,10 +363,25 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com"\s*>email@example.com</a> address';
$text = 'email@example.com address';
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$this->assertEquals($expected, $result);
$text = 'email@example.com address';
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = '(email@example.com) address';
$expected = '(<a href="mailto:email@example.com">email@example.com</a>) address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
@ -374,19 +389,19 @@ class TextHelperTest extends CakeTestCase {
$this->assertEquals($expected, $result);
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" \s*class="link">email@example.com</a> address';
$expected = 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertRegExp('#^' . $expected . '$#', $result);
$this->assertEquals($expected, $result);
$text = 'Text with düsentrieb@küchenschöhn-not-working.de address';
$expected = 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$this->assertEquals($expected, $result);
$text = 'Text with me@subdomain.küchenschöhn.de address';
$expected = 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertRegExp('#^' . $expected . '$#', $result);
$this->assertEquals($expected, $result);
}
/**

View file

@ -187,7 +187,7 @@ class TextHelper extends AppHelper {
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
$text = preg_replace_callback(
'/(?<=\s)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
'/(?<=\s|^|\()(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
array(&$this, '_insertPlaceholder'),
$text
);