URLs on the API site have recently changed to this format:

http://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/functi...

which doesn't get picked up as a valid link by the input format here.

Comments

joachim’s picture

So, of two things one is true:

A. Drupal 6's _filter_url() has a bug in it which causes it to not recognize a '!' in a URL. (I'd link to http://api.drupal.org/api/drupal/modules!filter!filter.module/function/_... ... but I can't.)

B. A '!' is not a valid character in a URL, and this is a new bug in API module.

joachim’s picture

Project: Drupal.org infrastructure » Drupal core
Version: » 6.x-dev
Component: api.drupal.org » filter.module

According to http://www.ietf.org/rfc/rfc3986.txt, a '!' is a sub-delim character. Whatever that is -- the spec doesn't really explain.

In which case it's a Drupal core bug. Those URLs work fine on D7. The '!' appears in the D6 regex, but perhaps there's an error in there somewhere?

joachim’s picture

Title: URLs to API site are no longer shown as links » URLs containing a '!' separator are not formatted as links

Updating title.

battlecrop’s picture

You can try by replacing ! of the url by its special code for example space is %20

bdragon’s picture

No, you shouldn't escape ! in a url.

$text = preg_replace_callback("`(<p>|<li>|<br\s*/?>|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(</p>|</li>|<br\s*/?>|[ \n\r\t\)]))`i", '_filter_url_parse_full_links', $text);

should probably be

$text = preg_replace_callback("`(<p>|<li>|<br\s*/?>|[ \n\r\t\(])((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#!?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(</p>|</li>|<br\s*/?>|[ \n\r\t\)]))`i", '_filter_url_parse_full_links', $text);

FWIW, to be fully compliant it should also support $ and ( ), but the parenthesis are problematic because the close paren is likely to occur both as the last character in the url (wikipedia disambiguation pages, as an example) and surrounding the link, so other than keeping track of any open parens, there isn't a good way to distinguish them.

greggles’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

I am uniquely gifted at taking other people's comments with code and turning them into patches.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Patch works for me. Thanks!

Drave Robber’s picture

sun’s picture

Priority: Major » Normal

Looks good to me as well.

sun’s picture

joachim’s picture

Please please please could this get committed, so that it can then be deployed on d.org?

It makes a total mockery of having an API site when we can't link to function documentation in issues!

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: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 1480992_url_filter_allow_exclamations.patch, failed testing.

Status: Needs work » 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.