From ced8fb20a151b78794c692b5766954a540ab5153 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 24 Apr 2020 07:28:10 +0000 Subject: [PATCH] Code Modernization: Remove error suppression from `parse_url()` calls. Previously, the `@` operator was used to prevent possible warnings emitted by `parse_url()` in PHP < 5.3.3 when URL parsing failed. Now that the minimum version of PHP required by WordPress is 5.6.20, this is no longer needed. Props netpassprodsr, Howdy_McGee. Fixes #49980. See #24780. Built from https://develop.svn.wordpress.org/trunk@47617 git-svn-id: http://core.svn.wordpress.org/trunk@47392 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 12 ++++++------ wp-includes/class-http.php | 2 +- wp-includes/class-wp-http-cookie.php | 2 +- wp-includes/class-wp-http-proxy.php | 6 +----- wp-includes/comment.php | 11 +++++++---- wp-includes/feed.php | 2 +- wp-includes/functions.php | 6 +++--- wp-includes/http.php | 9 +++------ wp-includes/pluggable.php | 3 +-- wp-includes/version.php | 2 +- 10 files changed, 25 insertions(+), 30 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 4d373e13bd..85ffa7d93c 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -67,7 +67,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $requested_url .= $_SERVER['REQUEST_URI']; } - $original = @parse_url( $requested_url ); + $original = parse_url( $requested_url ); if ( false === $original ) { return; } @@ -407,7 +407,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); if ( $redirect_url && ! empty( $redirect['query'] ) ) { parse_str( $redirect['query'], $_parsed_query ); - $redirect = @parse_url( $redirect_url ); + $redirect = parse_url( $redirect_url ); if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { parse_str( $redirect['query'], $_parsed_redirect_query ); @@ -425,11 +425,11 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { } if ( $redirect_url ) { - $redirect = @parse_url( $redirect_url ); + $redirect = parse_url( $redirect_url ); } // www.example.com vs. example.com - $user_home = @parse_url( home_url() ); + $user_home = parse_url( home_url() ); if ( ! empty( $user_home['host'] ) ) { $redirect['host'] = $user_home['host']; } @@ -637,7 +637,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { * @return string The altered query string */ function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) { - $parsed_url = @parse_url( $url ); + $parsed_url = parse_url( $url ); if ( ! empty( $parsed_url['query'] ) ) { parse_str( $parsed_url['query'], $parsed_query ); foreach ( $args_to_check as $qv ) { @@ -660,7 +660,7 @@ function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $ur * @return string The altered URL. */ function strip_fragment_from_url( $url ) { - $parsed_url = @parse_url( $url ); + $parsed_url = parse_url( $url ); if ( ! empty( $parsed_url['host'] ) ) { // This mirrors code in redirect_canonical(). It does not handle every case. $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index fd759b7347..51115bbf1a 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -269,7 +269,7 @@ class WP_Http { } } - $arrURL = @parse_url( $url ); + $arrURL = parse_url( $url ); if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); diff --git a/wp-includes/class-wp-http-cookie.php b/wp-includes/class-wp-http-cookie.php index fb3861383e..430bc47119 100644 --- a/wp-includes/class-wp-http-cookie.php +++ b/wp-includes/class-wp-http-cookie.php @@ -93,7 +93,7 @@ class WP_Http_Cookie { */ public function __construct( $data, $requested_url = '' ) { if ( $requested_url ) { - $arrURL = @parse_url( $requested_url ); + $arrURL = parse_url( $requested_url ); } if ( isset( $arrURL['host'] ) ) { $this->domain = $arrURL['host']; diff --git a/wp-includes/class-wp-http-proxy.php b/wp-includes/class-wp-http-proxy.php index 37752c001a..f9b97c865e 100644 --- a/wp-includes/class-wp-http-proxy.php +++ b/wp-includes/class-wp-http-proxy.php @@ -167,11 +167,7 @@ class WP_HTTP_Proxy { * @return bool True, to send through the proxy and false if, the proxy should not be used. */ public function send_through_proxy( $uri ) { - /* - * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. - * This will be displayed on sites, which is not reasonable. - */ - $check = @parse_url( $uri ); + $check = parse_url( $uri ); // Malformed URL, can not process, but this could mean ssl, so let through anyway. if ( false === $check ) { diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 8eb1c97da5..87ed753c17 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -580,7 +580,9 @@ function wp_set_comment_cookies( $comment, $user, $cookies_consent = true ) { * @param int $seconds Comment cookie lifetime. Default 30000000. */ $comment_cookie_lifetime = time() + apply_filters( 'comment_cookie_lifetime', 30000000 ); - $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); + + $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); + setcookie( 'comment_author_' . COOKIEHASH, $comment->comment_author, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); setcookie( 'comment_author_email_' . COOKIEHASH, $comment->comment_author_email, $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); setcookie( 'comment_author_url_' . COOKIEHASH, esc_url( $comment->comment_author_url ), $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); @@ -2852,9 +2854,10 @@ function pingback( $content, $post_id ) { foreach ( (array) $post_links_temp as $link_test ) { // If we haven't pung it already and it isn't a link to itself. if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) != $post->ID ) - // Also, let's never ping local attachments. - && ! is_local_attachment( $link_test ) ) { - $test = @parse_url( $link_test ); + // Also, let's never ping local attachments. + && ! is_local_attachment( $link_test ) + ) { + $test = parse_url( $link_test ); if ( $test ) { if ( isset( $test['query'] ) ) { $post_links[] = $link_test; diff --git a/wp-includes/feed.php b/wp-includes/feed.php index 49c262d1ed..41bb04c288 100644 --- a/wp-includes/feed.php +++ b/wp-includes/feed.php @@ -622,7 +622,7 @@ function rss2_site_icon() { * @return string Correct link for the atom:self element. */ function get_self_link() { - $host = @parse_url( home_url() ); + $host = parse_url( home_url() ); return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ); } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index bc9f276b89..1d3b2c74bc 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -866,7 +866,7 @@ function do_enclose( $content = null, $post ) { foreach ( (array) $post_links_temp as $link_test ) { // If we haven't pung it already. if ( ! in_array( $link_test, $pung, true ) ) { - $test = @parse_url( $link_test ); + $test = parse_url( $link_test ); if ( false === $test ) { continue; } @@ -901,7 +901,7 @@ function do_enclose( $content = null, $post ) { $allowed_types = array( 'video', 'audio' ); // Check to see if we can figure out the mime type from the extension. - $url_parts = @parse_url( $url ); + $url_parts = parse_url( $url ); if ( false !== $url_parts ) { $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); if ( ! empty( $extension ) ) { @@ -1240,7 +1240,7 @@ function add_magic_quotes( $array ) { * @return string|false HTTP content. False on failure. */ function wp_remote_fopen( $uri ) { - $parsed_url = @parse_url( $uri ); + $parsed_url = parse_url( $uri ); if ( ! $parsed_url || ! is_array( $parsed_url ) ) { return false; diff --git a/wp-includes/http.php b/wp-includes/http.php index 792482cd9f..c2678afae1 100644 --- a/wp-includes/http.php +++ b/wp-includes/http.php @@ -522,7 +522,7 @@ function wp_http_validate_url( $url ) { return false; } - $parsed_url = @parse_url( $url ); + $parsed_url = parse_url( $url ); if ( ! $parsed_url || empty( $parsed_url['host'] ) ) { return false; } @@ -535,7 +535,7 @@ function wp_http_validate_url( $url ) { return false; } - $parsed_home = @parse_url( get_option( 'home' ) ); + $parsed_home = parse_url( get_option( 'home' ) ); if ( isset( $parsed_home['host'] ) ) { $same_host = strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ); @@ -654,9 +654,6 @@ function ms_allowed_http_request_hosts( $is_external, $host ) { * in the query are being handled inconsistently. This function works around those * differences as well. * - * Error suppression is used as prior to PHP 5.3.3, an E_WARNING would be generated - * when URL parsing failed. - * * @since 4.4.0 * @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`. * @@ -684,7 +681,7 @@ function wp_parse_url( $url, $component = -1 ) { $url = 'placeholder://placeholder' . $url; } - $parts = @parse_url( $url ); + $parts = parse_url( $url ); if ( false === $parts ) { // Parsing failure. diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index c5899c6c36..e484923a42 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1423,8 +1423,7 @@ if ( ! function_exists( 'wp_validate_redirect' ) ) : $cut = strpos( $location, '?' ); $test = $cut ? substr( $location, 0, $cut ) : $location; - // @-operator is used to prevent possible warnings in PHP < 5.3.3. - $lp = @parse_url( $test ); + $lp = parse_url( $test ); // Give up if malformed URL. if ( false === $lp ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c91d4326b6..1329c8df24 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-47616'; +$wp_version = '5.5-alpha-47617'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.