diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 1590899ce5..637a13381e 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -2730,19 +2730,19 @@ function wp_rel_nofollow( $text ) { */ function wp_rel_nofollow_callback( $matches ) { $text = $matches[1]; - $atts = shortcode_parse_atts( $matches[1] ); + $atts = wp_kses_hair( $matches[1], wp_allowed_protocols() ); $rel = 'nofollow'; if ( ! empty( $atts['href'] ) ) { - if ( in_array( strtolower( wp_parse_url( $atts['href'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) { - if ( strtolower( wp_parse_url( $atts['href'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) { + if ( in_array( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_SCHEME ) ), array( 'http', 'https' ), true ) ) { + if ( strtolower( wp_parse_url( $atts['href']['value'], PHP_URL_HOST ) ) === strtolower( wp_parse_url( home_url(), PHP_URL_HOST ) ) ) { return ""; } } } if ( ! empty( $atts['rel'] ) ) { - $parts = array_map( 'trim', explode( ' ', $atts['rel'] ) ); + $parts = array_map( 'trim', explode( ' ', $atts['rel']['value'] ) ); if ( false === array_search( 'nofollow', $parts ) ) { $parts[] = 'nofollow'; } @@ -2751,7 +2751,11 @@ function wp_rel_nofollow_callback( $matches ) { $html = ''; foreach ( $atts as $name => $value ) { - $html .= "{$name}=\"" . esc_attr( $value ) . "\" "; + if ( isset( $value['vless'] ) && 'y' === $value['vless'] ) { + $html .= $name . ' '; + } else { + $html .= "{$name}=\"" . esc_attr( $value['value'] ) . '" '; + } } $text = trim( $html ); } diff --git a/tests/phpunit/tests/formatting/WPRelNoFollow.php b/tests/phpunit/tests/formatting/WPRelNoFollow.php index bd13a83b5e..9dbea786df 100644 --- a/tests/phpunit/tests/formatting/WPRelNoFollow.php +++ b/tests/phpunit/tests/formatting/WPRelNoFollow.php @@ -74,4 +74,10 @@ class Tests_Rel_No_Follow extends WP_UnitTestCase { ), ); } + + public function test_append_no_follow_with_valueless_attribute() { + $content = '

This is some cool Code

'; + $expected = '

This is some cool Code

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