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
This commit is contained in:
parent
8226fe338f
commit
bda3af14b0
@ -3040,8 +3040,10 @@ function wp_rel_nofollow_callback( $matches ) {
|
|||||||
function wp_targeted_link_rel( $text ) {
|
function wp_targeted_link_rel( $text ) {
|
||||||
// Don't run (more expensive) regex if no links with targets.
|
// Don't run (more expensive) regex if no links with targets.
|
||||||
if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a ' ) !== false ) {
|
if ( stripos( $text, 'target' ) !== false && stripos( $text, '<a ' ) !== false ) {
|
||||||
|
if ( ! is_serialized( $text ) ) {
|
||||||
$text = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text );
|
$text = preg_replace_callback( '|<a\s([^>]*target\s*=[^>]*)>|i', 'wp_targeted_link_rel_callback', $text );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
@ -127,4 +127,16 @@ class Tests_Targeted_Link_Rel extends WP_UnitTestCase {
|
|||||||
$expected = '<p>Links: <a href=\'\/\' target=_blank rel=\'noopener noreferrer\'>No rel<\/a><\/p>';
|
$expected = '<p>Links: <a href=\'\/\' target=_blank rel=\'noopener noreferrer\'>No rel<\/a><\/p>';
|
||||||
$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
|
$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:"<p>Links: <a href="/" target="_blank">No Rel</a></p>";}';
|
||||||
|
$expected = 'a:1:{s:4:"html";s:52:"<p>Links: <a href="/" target="_blank">No Rel</a></p>";}';
|
||||||
|
$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user