diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 9f4597d177..2348623854 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -2350,10 +2350,12 @@ function wp_rel_nofollow_callback( $matches ) {
$atts = shortcode_parse_atts( $matches[1] );
$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['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 ) ) ) {
+ return "";
+ }
+ }
}
if ( ! empty( $atts['rel'] ) ) {
@@ -2366,11 +2368,11 @@ function wp_rel_nofollow_callback( $matches ) {
$html = '';
foreach ( $atts as $name => $value ) {
- $html .= "{$name}=\"$value\" ";
+ $html .= "{$name}=\"" . esc_attr( $value ) . "\" ";
}
$text = trim( $html );
}
- return "";
+ return "";
}
/**