diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 690b95a84d..240a21a928 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -2259,8 +2259,23 @@ function wp_rel_nofollow( $text ) { */ function wp_rel_nofollow_callback( $matches ) { $text = $matches[1]; - $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); - return ""; + $atts = shortcode_parse_atts( $matches[1] ); + $rel = 'nofollow'; + if ( ! empty( $atts['rel'] ) ) { + $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); + if ( false === array_search( 'nofollow', $parts ) ) { + $parts[] = 'nofollow'; + } + $rel = implode( ' ', $parts ); + unset( $atts['rel'] ); + + $html = ''; + foreach ( $atts as $name => $value ) { + $html .= "{$name}=\"$value\" "; + } + $text = trim( $html ); + } + return ""; } /** diff --git a/tests/phpunit/tests/formatting/WPRelNoFollow.php b/tests/phpunit/tests/formatting/WPRelNoFollow.php new file mode 100644 index 0000000000..8d6a514e8e --- /dev/null +++ b/tests/phpunit/tests/formatting/WPRelNoFollow.php @@ -0,0 +1,18 @@ +This is some cool Code

'; + $expected = '

This is some cool Code

'; + $this->assertEquals( $expected, wp_rel_nofollow( $content ) ); + } + + public function test_convert_no_follow() { + $content = '

This is some cool Code

'; + $expected = '

This is some cool Code

'; + $this->assertEquals( $expected, wp_rel_nofollow( $content ) ); + } +} \ No newline at end of file