In "Filtered HTML" input format (HTML Filter + URL filter), if a URL is followed immediately by a filtered tag, it is not changed to a hyperlink.

E.g. http://drupal.org/Only local images are allowed.

This appears to be because the URL filter runs before the HTML filter, and the IMG tag breaks the regex.

Comments

lyricnz’s picture

Hehehe, this issue report actually demonstrates the problem. The markup I put in the body actually read

http://drupal.org/<img src="xxx">

but a URL like that would normally be highlighted. Test http://drupal.org/ test.

lyricnz’s picture

PS: this bug doesn't happen with Drupal 7.

lyricnz’s picture

Bump. Annoying bug.

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: Active » 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.