Using auto_link() to output the copy from a CMS controlled page onto the front end. I have 2 email addresses, recruit@ and bankrecruit@ in the stored copy.
When I look at the front end the first email, recruit@, is auto_linked to become a linked email address but the second one becomes bank followed by the recruit@ email link. This is obviously not what I expected.
auto_link() is matching all cases of recruit@ in which case the bankrecruit@ is being converted as it finds recruit@ first and converts that.
If I remove the recruit@ then bankrecruit@ works fine. Also if I change the name to bank@ then both addresses work as expected.
Is there a resolution for this?
<p>This is the address a@test.com</p>
<p>This is the second address ba@test.com</p>
And the script is:
auto_link($content)
As @cryptic pointed, it is a bug in the auto_link method. (See source) They are finding all email address in the output and then, they do a replace all (str_replace
) with the anchored version. So...
<p>This is the address a@test.com</p>
<p>This is the second address ba@test.com</p>
becomes
<p>This is the address <a ...>a@test.com</a></p>
<p>This is the second address b<a ...>a@test.com</a></p>
on first pass for the email a@test.com
. On the second e-mail, they try to replace ba@test.com
with the anchored version, but the str_replace
can not find the address, it has already been replaced.
You could implement your own fix by :
For example:
$str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
becomes
$str = preg_replace('/' . $matches['0'][$i] . '/', safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str, 1);
That should fix it for you. I would advise against modifying the system's URL_Helper, you might run into some migration problems later on.
Hope this helps.