Add unit tests for links_add_target(). Alter the patterns in links_add_target() and _links_add_target() slightly based on learnings after running tests.

Props mdbitz.
Fixes #26164.



git-svn-id: https://develop.svn.wordpress.org/trunk@26328 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-11-22 16:24:25 +00:00
parent b209e63234
commit 1dc930ba13
2 changed files with 86 additions and 2 deletions
+2 -2
View File
@@ -3243,7 +3243,7 @@ function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
global $_links_add_target;
$_links_add_target = $target;
$tags = implode('|', (array)$tags);
return preg_replace_callback( "!<($tags)(.+?)>!i", '_links_add_target', $content );
return preg_replace_callback( "!<($tags)([^>]*)>!i", '_links_add_target', $content );
}
/**
@@ -3258,7 +3258,7 @@ function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
function _links_add_target( $m ) {
global $_links_add_target;
$tag = $m[1];
$link = preg_replace('|(target=([\'"])(.*?)\2)|i', '', $m[2]);
$link = preg_replace('|( target=([\'"])(.*?)\2)|i', '', $m[2]);
return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">';
}