From fbab7bd9c30fe6560bf1581d19f73001a90a4c06 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 27 Mar 2011 19:09:46 -0400 Subject: [PATCH] Fixing linking of emails that are missing tld's. They should not be turned into links. Test added. Fixes #1622 --- cake/libs/view/helpers/text.php | 2 +- cake/tests/cases/libs/view/helpers/text.test.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 7d25ea349..6aef14f8d 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -145,7 +145,7 @@ class TextHelper extends AppHelper { $atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]'; return preg_replace_callback( - '/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i', + '/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)+)/i', create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text); } diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 249f96749..d0250a135 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -320,6 +320,17 @@ class TextHelperTest extends CakeTestCase { $this->assertPattern('#^' . $expected . '$#', $result); } +/** + * test invalid email addresses. + * + * @return void + */ + function testAutoLinkEmailInvalid() { + $result = $this->Text->autoLinkEmails('this is a myaddress@gmx-de test'); + $expected = 'this is a myaddress@gmx-de test'; + $this->assertEqual($expected, $result); + } + /** * testHighlightCaseInsensitivity method *