Skip to content

Commit c36572d

Browse files
committed
PHP 8.1: download_url(): prevent "passing null to non-nullable" notice [1]
Includes removing duplicate function calls. I've verified that neither the `$url`, nor the `$url_filename` are changed between when they are first received/defined and when they are re-used, so there is no need to repeat the function calls.
1 parent 8e58f75 commit c36572d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/wp-admin/includes/file.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,11 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) {
11261126
return new WP_Error( 'http_no_url', __( 'Invalid URL Provided.' ) );
11271127
}
11281128

1129-
$url_filename = basename( parse_url( $url, PHP_URL_PATH ) );
1129+
$url_path = parse_url( $url, PHP_URL_PATH );
1130+
$url_filename = '';
1131+
if ( is_string( $url_path ) ) {
1132+
$url_filename = basename( $url_path );
1133+
}
11301134

11311135
$tmpfname = wp_tempnam( $url_filename );
11321136
if ( ! $tmpfname ) {
@@ -1212,7 +1216,6 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) {
12121216
// WordPress.org stores signatures at $package_url.sig.
12131217

12141218
$signature_url = false;
1215-
$url_path = parse_url( $url, PHP_URL_PATH );
12161219

12171220
if ( '.zip' === substr( $url_path, -4 ) || '.tar.gz' === substr( $url_path, -7 ) ) {
12181221
$signature_url = str_replace( $url_path, $url_path . '.sig', $url );
@@ -1243,7 +1246,7 @@ function download_url( $url, $timeout = 300, $signature_verification = false ) {
12431246
}
12441247

12451248
// Perform the checks.
1246-
$signature_verification = verify_file_signature( $tmpfname, $signature, basename( parse_url( $url, PHP_URL_PATH ) ) );
1249+
$signature_verification = verify_file_signature( $tmpfname, $signature, $url_filename );
12471250
}
12481251

12491252
if ( is_wp_error( $signature_verification ) ) {

0 commit comments

Comments
 (0)