Ticket #8300 (closed defect (bug): fixed)

Opened 3 years ago

Last modified 3 years ago

Add parentheses to the list of valid URL characters for make_clickable function

Reported by: josephscott Owned by: anonymous
Priority: normal Milestone: 2.8
Component: General Version: 2.7
Severity: normal Keywords: has-patch
Cc: josephscott

Description

The make_clickable currently doesn't work correctly for URLs with parentheses like these:

http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)
http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx

By adding () to the list of valid URL characters these URLs are correctly detected. I've included a simple patch to do just that.

Attachments

wp-includes--formatting.php.diff Download (953 bytes) - added by josephscott 3 years ago.
wp-includes--formatting.php.2.diff Download (1.7 KB) - added by josephscott 3 years ago.
make_clickable_parenthesis.diff Download (982 bytes) - added by filosofo 3 years ago.
leaner_make_url_clickable_cb.diff Download (1.5 KB) - added by filosofo 3 years ago.

Change History

comment:1 follow-up: ↓ 2   DD323 years ago

  • Version set to 2.7

You need to be careful about including parentheses in function to make links, As ( http://blah.com/) should not be matched as a link, only the insides, yet  http://blah.com/something(else)_another should..

There are some link parsing regular expressions around which deal with those cases specifically, somethin more robust might be required.

comment:2 in reply to: ↑ 1   josephscott3 years ago

Replying to DD32:

You need to be careful about including parentheses in function to make links, As ( http://blah.com/) should not be matched as a link, only the insides, yet  http://blah.com/something(else)_another should..

There are some link parsing regular expressions around which deal with those cases specifically, somethin more robust might be required.

Just so happens that I just wrote some code to deal with this, so that this:

My site (http://josephscott.org)

So that the the open and closing parens are not included as part of the URL, will still supporting parens inside the URL.

I've updated the patch to reflect this.

Actually, you can do this without having to modify _make_url_clickable_cb: just change the regex to capture a closing parenthesis at the end of the URL only if the entire URL is not preceded by an opening parenthesis.

make_clickable_parenthesis.diff gets all of the following examples right:

http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)
http://msdn.microsoft.com/en-us/library/aa752574(VS.85).aspx
My site (http://josephscott.org)

Actually, it occurred to me that we could make _make_url_clickable_cb even shorter, using the same regex technique to remove ending .,;:, as seen in patch leaner_make_url_clickable_cb.diff

I tried the changes in leaner_make_url_clickable_cb.diff and it failed to pick up the closing paren for this test case:

My (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) article

That got converted to:

My (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))</a> article

That last ) should have been outside the </a> tag.

I've refreshed the patch--try that.

Nicely done, that fixes the previous test case problem.

After more tests it turns out that the new regular expression doesn't work in PHP4. Something changed in PHP5 preg_replace_callback() that allow it to work.

Which tests in particular fail for PHP 4?

Sorry, this looks like a false alarm. Patch works on PHP4 as well.

  • Status changed from new to closed
  • Resolution set to fixed

(In [10562]) Handle links with parens in make_clickable(). Props filosofo. fixes #8300

Note: See TracTickets for help on using tickets.