A live example can be seen here: http://www.bluewavedigital.net/news/2-11-2008/twitter-integration

I don't know if it's only me, or what is going on here, but the @username link has two <a href> tags around it. I am using the latest stable build.

Code seen on that page:

<p>Hypothetically, <a href="http://twitter.com/ocdude"></a><a href="http://twitter.com/ocdude">@ocdude</a> will link to my account.</p>

Comments

amedee-1’s picture

The same happens for #hashtags.
This is the only error that stops my site from completely validating as XHTML Transitional.

amedee-1’s picture

Version: 6.x-2.0 » 6.x-2.x-dev

I have compared the source of the stable release and the dev release, and I have seen no differences in the code for the filter functions. So this problem also exists in dev.

abraham’s picture

It is caused by the regex in $matches[2] and $replacements[2] in twitter.module.

/**
 * This helper function converts Twitter-style @usernames and #hashtags into 
 * actual links.
 */
function twitter_link_filter($text, $prefix = '@', $destination = 'http://twitter.com/') {
  $matches = array(
    '/^' . $prefix . '([a-z0-9_]{0,15})/i',
    '/(\s+)' . $prefix . '([a-z0-9_]{0,15})/i',
    '/\>' . $prefix . '([a-z0-9_]{0,15})/i'
  );
  $replacements = array(
    '<a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
    '${1}<a href="' . $destination . '${2}">' . $prefix . '${2}</a>',
    '><a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
  );
  return preg_replace($matches, $replacements, $text); 
}

I'm not entirely sure what string it is trying to match but if you bump it to position 0 it fixes the issue.

  ...
  $matches = array(
    '/\>' . $prefix . '([a-z0-9_]{0,15})/i',
    '/^' . $prefix . '([a-z0-9_]{0,15})/i',
    '/(\s+)' . $prefix . '([a-z0-9_]{0,15})/i',
  );
  $replacements = array(
    '><a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
    '<a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
    '${1}<a href="' . $destination . '${2}">' . $prefix . '${2}</a>',
  );
  ...
sillygwailo’s picture

Patched based on poseurtech's proposed fix attached.

totkoo’s picture

#4 - Patch works for me! Thanks very much.

jaydub’s picture

Status: Active » Reviewed & tested by the community

works here too.

eaton’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.