From bda3af14b0f8f7b75c919c42727dcd510b05508c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 25 May 2019 12:04:28 +0000 Subject: [PATCH] Formatting: Don't run `wp_targeted_link_rel()` on entirely serialized content. Props birgire, elliotcondon. Fixes #46402. git-svn-id: https://develop.svn.wordpress.org/trunk@45408 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 4 +++- tests/phpunit/tests/formatting/WPTargetedLinkRel.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 ) ); + } + }