From f30e343b12856c270cfec79666e68650e9b99464 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Wed, 29 Jun 2016 21:04:25 +0000 Subject: [PATCH] Script Loader: Use `wp_parse_url()` to fix URL parsing failures for PHP < 5.4.7. See [37920]. See #34292. git-svn-id: https://develop.svn.wordpress.org/trunk@37922 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 222f248252..b6fc4d0cb9 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -2821,7 +2821,10 @@ function wp_resource_hints() { $url = esc_url( $url, array( 'http', 'https' ) ); if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { - $parsed = parse_url( $url ); + $parsed = wp_parse_url( $url ); + if ( empty( $parsed['host'] ) ) { + continue; + } if ( ! empty( $parsed['scheme'] ) ) { $url = $parsed['scheme'] . '://' . $parsed['host']; @@ -2847,30 +2850,20 @@ function wp_resource_hints_scripts_styles() { if ( is_object( $wp_scripts ) && ! empty( $wp_scripts->registered ) ) { foreach ( $wp_scripts->registered as $registered_script ) { - $src = $registered_script->src; - // Make sure the URL has a scheme, otherwise parse_url() could fail to pass the host. - if ( '//' == substr( $src, 0, 2 ) ) { - $src = set_url_scheme( $src ); - } + $parsed = wp_parse_url( $registered_script->src ); - $this_host = parse_url( $src, PHP_URL_HOST ); - if ( ! empty( $this_host ) && ! in_array( $this_host, $unique_hosts ) && $this_host !== $_SERVER['SERVER_NAME'] ) { - $unique_hosts[] = $this_host; + if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) { + $unique_hosts[] = $parsed['host']; } } } if ( is_object( $wp_styles ) && ! empty( $wp_styles->registered ) ) { foreach ( $wp_styles->registered as $registered_style ) { - $src = $registered_style->src; - // Make sure the URL has a scheme, otherwise parse_url() could fail to pass the host. - if ( '//' == substr( $src, 0, 2 ) ) { - $src = set_url_scheme( $src ); - } + $parsed = wp_parse_url( $registered_style->src ); - $this_host = parse_url( $src, PHP_URL_HOST ); - if ( ! empty( $this_host ) && ! in_array( $this_host, $unique_hosts ) && $this_host !== $_SERVER['SERVER_NAME'] ) { - $unique_hosts[] = $this_host; + if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) { + $unique_hosts[] = $parsed['host']; } } }