diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 45922d6f65..494c1b3e61 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -5243,7 +5243,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)((\s[^>]*)?)>!i", '_links_add_target', $content ); } /** diff --git a/tests/phpunit/tests/formatting/LinksAddTarget.php b/tests/phpunit/tests/formatting/LinksAddTarget.php index f0ad0585ac..391ad1736f 100644 --- a/tests/phpunit/tests/formatting/LinksAddTarget.php +++ b/tests/phpunit/tests/formatting/LinksAddTarget.php @@ -64,6 +64,30 @@ class Tests_Formatting_LinksAddTarget extends WP_UnitTestCase { array( 'span' ), 'MY CONTENT
SOME ADDITIONAL TEXT LINK HERE
END TEXT', ), + array( + 'MY CONTENT END TEXT', + null, + null, + 'MY CONTENT END TEXT', + ), + array( + 'MY CONTENT END TEXT', + null, + null, + 'MY CONTENT END TEXT', + ), + array( + 'MY CONTENT
SOME
ADDITIONAL TEXT LINK HERE END TEXT', + '_blank', + array( 'b' ), + 'MY CONTENT
SOME
ADDITIONAL TEXT LINK HERE END TEXT', + ), + array( + 'MY CONTENT
SOME
ADDITIONAL TEXT LINK HERE END TEXT', + '_blank', + array( 'b' ), + 'MY CONTENT
SOME
ADDITIONAL TEXT LINK HERE END TEXT', + ), ); }