diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 0800f0ef95..7d73481eab 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3040,7 +3040,9 @@ function wp_rel_nofollow_callback( $matches ) { function wp_targeted_link_rel( $text ) { // Don't run (more expensive) regex if no links with targets. if ( stripos( $text, 'target' ) !== false && stripos( $text, ']*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text ); + if ( ! is_serialized( $text ) ) { + $text = preg_replace_callback( '|]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text ); + } } return $text; diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php index 75f34aeda2..9d556630c0 100644 --- a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php +++ b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php @@ -127,4 +127,16 @@ class Tests_Targeted_Link_Rel extends WP_UnitTestCase { $expected = '

Links: No rel<\/a><\/p>'; $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); } + + /** + * Ensure entirely serialized content is ignored. + * + * @ticket 46402. + */ + public function test_ignore_entirely_serialized_content() { + $content = 'a:1:{s:4:"html";s:52:"

Links: No Rel

";}'; + $expected = 'a:1:{s:4:"html";s:52:"

Links: No Rel

";}'; + $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); + } + }