From e5f967ca997abbc971f697fad33e74396848dc28 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 12 Jul 2016 11:32:28 +0000 Subject: [PATCH] Resource Hints: Remove schemes from `dns-prefetch` resource hint outputs. "wordpress.org", "!http://wordpress.org", and "!https://wordpress.org" should all have the same DNS lookup. Also, replace `\r\n` with `\n` and ensure that invalid URLs are skipped. Props niallkennedy, peterwilsoncc. Fixes #37240. Built from https://develop.svn.wordpress.org/trunk@38036 git-svn-id: http://core.svn.wordpress.org/trunk@37977 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 20 ++++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index bf0614bd22..2bcdb43801 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2815,25 +2815,37 @@ function wp_resource_hints() { * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. */ $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); - $urls = array_unique( $urls ); - foreach ( $urls as $url ) { + foreach ( $urls as $key => $url ) { $url = esc_url( $url, array( 'http', 'https' ) ); + if ( ! $url ) { + unset( $urls[ $key ] ); + continue; + } if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { $parsed = wp_parse_url( $url ); if ( empty( $parsed['host'] ) ) { + unset( $urls[ $key ] ); continue; } - if ( ! empty( $parsed['scheme'] ) ) { + if ( 'dns-prefetch' === $relation_type ) { + $url = '//' . $parsed['host']; + } else if ( ! empty( $parsed['scheme'] ) ) { $url = $parsed['scheme'] . '://' . $parsed['host']; } else { $url = $parsed['host']; } } - printf( "\r\n", $relation_type, $url ); + $urls[ $key ] = $url; + } + + $urls = array_unique( $urls ); + + foreach ( $urls as $url ) { + printf( "\n", $relation_type, $url ); } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 862ff25ef9..bf34f2e8cc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta2-38035'; +$wp_version = '4.6-beta2-38036'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.