Development

Changeset 33022

You must first sign up to be able to contribute.

Changeset 33022

Show
Ignore:
Timestamp:
09/15/11 07:27:12 (3 years ago)
Author:
fabien
Message:

[1.4] fixed auto_link_text() when an email address is already linked (closes #9915, based on a patch from klemens_u)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.4/lib/helper/TextHelper.php

    r31895 r33022  
    284284function _auto_link_email_addresses($text) 
    285285{ 
    286   return preg_replace('/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/', '<a href="mailto:\\1">\\1</a>', $text); 
    287 
     286  // Taken from http://snippets.dzone.com/posts/show/6156 
     287  return preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $text); 
     288 
     289  // Removed since it destroys already linked emails  
     290  // Example:   <a href="mailto:me@example.com">bar</a> gets <a href="mailto:me@example.com">bar</a> gets <a href="mailto:<a href="mailto:me@example.com">bar</a> 
     291  //return preg_replace('/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/', '<a href="mailto:\\1">\\1</a>', $text); 
     292
  • branches/1.4/test/unit/helper/TextHelperTest.php

    r31895 r33022  
    1414require_once(dirname(__FILE__).'/../../../lib/helper/TextHelper.php'); 
    1515 
    16 $t = new lime_test(54); 
     16$t = new lime_test(56); 
    1717 
    1818// truncate_text() 
     
    135135$t->is(auto_link_text('<p>http://twitter.com/#!/fabpot</p>'),'<p><a href="http://twitter.com/#!/fabpot">http://twitter.com/#!/fabpot</a></p>',"auto_link_text() converts URLs with complex fragments to links"); 
    136136$t->is(auto_link_text('<p>http://twitter.com/#!/fabpot is Fabien Potencier on Twitter</p>'),'<p><a href="http://twitter.com/#!/fabpot">http://twitter.com/#!/fabpot</a> is Fabien Potencier on Twitter</p>',"auto_link_text() converts URLs with complex fragments and trailing text to links"); 
    137  
     137$t->is(auto_link_text('hello '.$email_result, 'email_addresses'), 'hello '.$email_result, "auto_link_text() does not double-link emails"); 
     138$t->is(auto_link_text('<p>Link '.$link_result.'</p>'), '<p>Link '.$link_result.'</p>', "auto_link_text() does not double-link emails");