diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index ac28d347f0..0ad1b5d583 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -2336,7 +2336,14 @@ function wp_rel_nofollow( $text ) { function wp_rel_nofollow_callback( $matches ) { $text = $matches[1]; $atts = shortcode_parse_atts( $matches[1] ); - $rel = 'nofollow'; + $rel = 'nofollow'; + + if ( preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'http' ) ) . ')%i', $text ) || + preg_match( '%href=["\'](' . preg_quote( set_url_scheme( home_url(), 'https' ) ) . ')%i', $text ) + ) { + return ""; + } + if ( ! empty( $atts['rel'] ) ) { $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); if ( false === array_search( 'nofollow', $parts ) ) { diff --git a/tests/phpunit/tests/formatting/WPRelNoFollow.php b/tests/phpunit/tests/formatting/WPRelNoFollow.php index 821bb936a1..bd13a83b5e 100644 --- a/tests/phpunit/tests/formatting/WPRelNoFollow.php +++ b/tests/phpunit/tests/formatting/WPRelNoFollow.php @@ -22,4 +22,56 @@ class Tests_Rel_No_Follow extends WP_UnitTestCase { $expected = '

This is some cool Code

'; $this->assertEquals( $expected, wp_rel_nofollow( $content ) ); } -} \ No newline at end of file + + /** + * @ticket 11360 + * @dataProvider data_wp_rel_nofollow + */ + public function test_wp_rel_nofollow( $input, $output ) { + return $this->assertEquals( wp_slash( $output ), wp_rel_nofollow( $input ) ); + } + + public function data_wp_rel_nofollow() { + $home_url_http = set_url_scheme( home_url(), 'http' ); + $home_url_https = set_url_scheme( home_url(), 'https' ); + + return array( + array( + 'Double Quotes', + 'Double Quotes', + ), + array( + 'Double Quotes', + 'Double Quotes', + ), + array( + "Single Quotes", + "Single Quotes", + ), + array( + 'Multiple attributes', + 'Multiple attributes', + ), + array( + 'Multiple attributes', + 'Multiple attributes', + ), + array( + 'Multiple attributes', + 'Multiple attributes', + ), + array( + 'Everything at once', + 'Everything at once', + ), + array( + 'Home URL (http)', + 'Home URL (http)', + ), + array( + 'Home URL (https)', + 'Home URL (https)', + ), + ); + } +}