The text

 http://gooogle.com

Will fail to turn link a link, even though visually the nbsp is a space.

Real example:
without nbsp: http://gooogle.com
with nbsp:  http://gooogle.com

Not an issue in d7+

CommentFileSizeAuthor
drupal_filter_url_nbsp.patch1.89 KBhefox

Comments

Sepero’s picture

Here's a fix. Go into modules/filter/filter.module and replace the function _filter_url with this:

function _filter_url($text, $format) {
  // Pass length to regexp callback
  _filter_url_trim(NULL, variable_get('filter_url_length_'. $format, 72));

  $text = ' '. $text .' ';

  $head = "(<p>|<li>|<br\s*/?>|[\s\(]|&nbsp;)";
  $tail = "([.,?!]*?)(?=([\s\)\<]))";
  $url_protocol = "http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://";
  $url_address = "[^\s\)\<@]*[^\s\)\<\,,?!]";
  // RFC3490 allows for unicode characters in email addresses. http://www.faqs.org/rfcs/rfc3490.html
  $email_address = "[^\s@\(\)\<\>]";
  
  // Match absolute URLs.
  $text = preg_replace_callback("`$head(($url_protocol)($url_address))$tail`i", '_filter_url_parse_full_links', $text);

  // Match e-mail addresses.
  $text = preg_replace("`$head($email_address+@$email_address+\.$email_address{2,4})$tail`i", '\1<a href="mailto:\2">\2</a>\3', $text);

  // Match www domains/addresses.
  $text = preg_replace_callback("`$head(www\.$url_address)$tail`i", '_filter_url_parse_partial_links', $text);
  $text = substr($text, 1, -1);

  return $text;
}

It fixes all these open bugs:
https://drupal.org/node/550464
https://drupal.org/node/2016089
https://drupal.org/node/1899246
https://drupal.org/node/1480992
https://drupal.org/node/1055864

It also fixes unknown/unmarked bugs:
Can't use foreign characters in email addresses.
Can't use many valid characters like '$%' in email addresses.
Can't preceed www web addresses with an html break.
Many html codes can't be used to end a url or email link.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.