[wp-trac] [WordPress Trac] #51313: Incorrect regular expression in links_add_target function

WordPress Trac noreply at wordpress.org
Tue Sep 15 11:20:41 UTC 2020


#51313: Incorrect regular expression in links_add_target function
--------------------------+-----------------------------
 Reporter:  antonlukin    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  5.5.1
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 `links_add_target` function relies on a regular expression `
 "!<($tags)([^>]*)>!i"`. It ignores cases where a tag is part of another
 tag, for example `aside`.

 {{{
 $content = 'test <aside>test</aside> test';
 $content = links_add_target( $content, '_blank', array( 'a' ) );
 }}}

 This code return `test <aside target="_blank">test</aside> test` but it
 shouldn't.

 Possible solution is to replace regexp with `!<($tags)(\s[^>]*)?>!i`

 [https://developer.wordpress.org/reference/functions/links_add_target/]

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


More information about the wp-trac mailing list