Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#8300 closed defect (bug) (fixed)

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

Reported by: josephscott's profile josephscott Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch
Focuses: Cc:

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 (4)

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

Download all attachments as: .zip

Change History (15)

#1 follow-up: @DD32
16 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.

#2 in reply to: ↑ 1 @josephscott
16 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.

#3 @filosofo
16 years ago

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)

#4 @filosofo
16 years ago

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

#5 @josephscott
16 years ago

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.

#6 @filosofo
16 years ago

I've refreshed the patch--try that.

#7 @josephscott
16 years ago

Nicely done, that fixes the previous test case problem.

#8 @josephscott
16 years ago

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.

#9 @filosofo
16 years ago

Which tests in particular fail for PHP 4?

#10 @josephscott
16 years ago

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

#11 @automattor
16 years ago

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

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

Note: See TracTickets for help on using tickets.