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
This commit is contained in:
Sergey Biryukov 2020-04-24 07:28:10 +00:00
parent 0dc461c72e
commit ced8fb20a1
10 changed files with 25 additions and 30 deletions

View File

@ -67,7 +67,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
$requested_url .= $_SERVER['REQUEST_URI']; $requested_url .= $_SERVER['REQUEST_URI'];
} }
$original = @parse_url( $requested_url ); $original = parse_url( $requested_url );
if ( false === $original ) { if ( false === $original ) {
return; return;
} }
@ -407,7 +407,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
if ( $redirect_url && ! empty( $redirect['query'] ) ) { if ( $redirect_url && ! empty( $redirect['query'] ) ) {
parse_str( $redirect['query'], $_parsed_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'] ) ) { if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) {
parse_str( $redirect['query'], $_parsed_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 ) { if ( $redirect_url ) {
$redirect = @parse_url( $redirect_url ); $redirect = parse_url( $redirect_url );
} }
// www.example.com vs. example.com // www.example.com vs. example.com
$user_home = @parse_url( home_url() ); $user_home = parse_url( home_url() );
if ( ! empty( $user_home['host'] ) ) { if ( ! empty( $user_home['host'] ) ) {
$redirect['host'] = $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 * @return string The altered query string
*/ */
function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) { 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'] ) ) { if ( ! empty( $parsed_url['query'] ) ) {
parse_str( $parsed_url['query'], $parsed_query ); parse_str( $parsed_url['query'], $parsed_query );
foreach ( $args_to_check as $qv ) { 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. * @return string The altered URL.
*/ */
function strip_fragment_from_url( $url ) { function strip_fragment_from_url( $url ) {
$parsed_url = @parse_url( $url ); $parsed_url = parse_url( $url );
if ( ! empty( $parsed_url['host'] ) ) { if ( ! empty( $parsed_url['host'] ) ) {
// This mirrors code in redirect_canonical(). It does not handle every case. // This mirrors code in redirect_canonical(). It does not handle every case.
$url = $parsed_url['scheme'] . '://' . $parsed_url['host']; $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];

View File

@ -269,7 +269,7 @@ class WP_Http {
} }
} }
$arrURL = @parse_url( $url ); $arrURL = parse_url( $url );
if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { if ( empty( $url ) || empty( $arrURL['scheme'] ) ) {
$response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );

View File

@ -93,7 +93,7 @@ class WP_Http_Cookie {
*/ */
public function __construct( $data, $requested_url = '' ) { public function __construct( $data, $requested_url = '' ) {
if ( $requested_url ) { if ( $requested_url ) {
$arrURL = @parse_url( $requested_url ); $arrURL = parse_url( $requested_url );
} }
if ( isset( $arrURL['host'] ) ) { if ( isset( $arrURL['host'] ) ) {
$this->domain = $arrURL['host']; $this->domain = $arrURL['host'];

View File

@ -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. * @return bool True, to send through the proxy and false if, the proxy should not be used.
*/ */
public function send_through_proxy( $uri ) { public function send_through_proxy( $uri ) {
/* $check = parse_url( $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 );
// Malformed URL, can not process, but this could mean ssl, so let through anyway. // Malformed URL, can not process, but this could mean ssl, so let through anyway.
if ( false === $check ) { if ( false === $check ) {

View File

@ -580,7 +580,9 @@ function wp_set_comment_cookies( $comment, $user, $cookies_consent = true ) {
* @param int $seconds Comment cookie lifetime. Default 30000000. * @param int $seconds Comment cookie lifetime. Default 30000000.
*/ */
$comment_cookie_lifetime = time() + apply_filters( 'comment_cookie_lifetime', 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_' . 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_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 ); 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 ) { foreach ( (array) $post_links_temp as $link_test ) {
// If we haven't pung it already and it isn't a link to itself. // 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 ) if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) != $post->ID )
// Also, let's never ping local attachments. // Also, let's never ping local attachments.
&& ! is_local_attachment( $link_test ) ) { && ! is_local_attachment( $link_test )
$test = @parse_url( $link_test ); ) {
$test = parse_url( $link_test );
if ( $test ) { if ( $test ) {
if ( isset( $test['query'] ) ) { if ( isset( $test['query'] ) ) {
$post_links[] = $link_test; $post_links[] = $link_test;

View File

@ -622,7 +622,7 @@ function rss2_site_icon() {
* @return string Correct link for the atom:self element. * @return string Correct link for the atom:self element.
*/ */
function get_self_link() { 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'] ) ); return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) );
} }

View File

@ -866,7 +866,7 @@ function do_enclose( $content = null, $post ) {
foreach ( (array) $post_links_temp as $link_test ) { foreach ( (array) $post_links_temp as $link_test ) {
// If we haven't pung it already. // If we haven't pung it already.
if ( ! in_array( $link_test, $pung, true ) ) { if ( ! in_array( $link_test, $pung, true ) ) {
$test = @parse_url( $link_test ); $test = parse_url( $link_test );
if ( false === $test ) { if ( false === $test ) {
continue; continue;
} }
@ -901,7 +901,7 @@ function do_enclose( $content = null, $post ) {
$allowed_types = array( 'video', 'audio' ); $allowed_types = array( 'video', 'audio' );
// Check to see if we can figure out the mime type from the extension. // 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 ) { if ( false !== $url_parts ) {
$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); $extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION );
if ( ! empty( $extension ) ) { if ( ! empty( $extension ) ) {
@ -1240,7 +1240,7 @@ function add_magic_quotes( $array ) {
* @return string|false HTTP content. False on failure. * @return string|false HTTP content. False on failure.
*/ */
function wp_remote_fopen( $uri ) { function wp_remote_fopen( $uri ) {
$parsed_url = @parse_url( $uri ); $parsed_url = parse_url( $uri );
if ( ! $parsed_url || ! is_array( $parsed_url ) ) { if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
return false; return false;

View File

@ -522,7 +522,7 @@ function wp_http_validate_url( $url ) {
return false; return false;
} }
$parsed_url = @parse_url( $url ); $parsed_url = parse_url( $url );
if ( ! $parsed_url || empty( $parsed_url['host'] ) ) { if ( ! $parsed_url || empty( $parsed_url['host'] ) ) {
return false; return false;
} }
@ -535,7 +535,7 @@ function wp_http_validate_url( $url ) {
return false; return false;
} }
$parsed_home = @parse_url( get_option( 'home' ) ); $parsed_home = parse_url( get_option( 'home' ) );
if ( isset( $parsed_home['host'] ) ) { if ( isset( $parsed_home['host'] ) ) {
$same_host = strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['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 * in the query are being handled inconsistently. This function works around those
* differences as well. * 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.4.0
* @since 4.7.0 The `$component` parameter was added for parity with PHP's `parse_url()`. * @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; $url = 'placeholder://placeholder' . $url;
} }
$parts = @parse_url( $url ); $parts = parse_url( $url );
if ( false === $parts ) { if ( false === $parts ) {
// Parsing failure. // Parsing failure.

View File

@ -1423,8 +1423,7 @@ if ( ! function_exists( 'wp_validate_redirect' ) ) :
$cut = strpos( $location, '?' ); $cut = strpos( $location, '?' );
$test = $cut ? substr( $location, 0, $cut ) : $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. // Give up if malformed URL.
if ( false === $lp ) { if ( false === $lp ) {

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.