[wp-trac] [WordPress Trac] #45702: make_clickable() doesn't handle linked text being a URL with spaces within it

WordPress Trac noreply at wordpress.org
Wed Dec 19 07:22:43 UTC 2018


#45702: make_clickable() doesn't handle linked text being a URL with spaces within
it
--------------------------+-----------------------------
 Reporter:  dd32          |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  low           |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:
 Severity:  trivial       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 As reported in https://meta.trac.wordpress.org/ticket/3998
 > {{{
 > <a href="https://codex.wordpress.org/Roles and
 Capabilities">https://codex.wordpress.org/Roles and Capabilities</a>
 > }}}
 > turns into:
 > {{{
 > <a href="https://codex.wordpress.org/Roles and Capabilities"
 rel="nofollow"></a><a href="https://codex.wordpress.org/Roles"
 rel="nofollow">https://codex.wordpress.org/Roles</a> and Capabilities
 > }}}
 > Looks like either `make_clickable()` or `bbp_make_clickable()` is trying
 to make the URL clickable without taking the existing `<a>` tag into
 account.

 As I've commented on the ticket:

 ----

 This is a problem in `bbp_make_clickable()`, but is also present in
 `make_clickable()`.

 Given the input string of `<a href="https://codex.wordpress.org/Roles and
 Capabilities">https://codex.wordpress.org/Roles and Capabilities</a>` both
 will return the invalid output.

 Both contain the following to correct it:
 {{{
 return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a
 [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r );
 }}}
 But as the resulting HTML is the following it's not matched (due to the
 `</a></a>` - which assumes that neither the linked text never has spaces
 or isn't a URL)
 {{{
 <a href="https://codex.wordpress.org/Roles and Capabilities"><a
 href="https://codex.wordpress.org/Roles"
 rel="nofollow">https://codex.wordpress.org/Roles</a> and Capabilities</a>
 }}}

 Adjusting the regular expression to the following does work however for
 this specific case:
 {{{
 return preg_replace( '#(<a([ \r\n\t]+[^>]+?>|>))<a
 [^>]+?>([^>]+?)</a>([^<]*)</a>#i', "$1$3$4</a>", $r );
 }}}

 As a work around, you can remove the spaces from the linked text, which
 avoids it:
 `<a href="https://codex.wordpress.org/Roles and
 Capabilities">https://codex.wordpress.org/Roles and Capabilities</a>`.

 ----

 Also created https://bbpress.trac.wordpress.org/ticket/3237

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45702>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list