From e16eaa49359d7a08d39fd17365401a7f378af9b5 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Fri, 10 Sep 2021 17:43:57 +0000 Subject: [PATCH] Code Modernization: Fix "passing null to non-nullable" deprecation notices in `WP_Http::normalize_cookies()`. The `Requests_Cookie` class expects valid - non-`null` - attributes to be passed, either as an array or as a `Requests_Utility_CaseInsensitiveDictionary` object. However, the `WP_Http_Cookie::get_attributes()` explicitly sets the `expires`, `path` and `domain` index keys in an array with values which _may_ be `null`. This will cause `strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated`-like errors when the attributes are passed to the `Requests_Cookie` class. Note: a `null` value for `path` would generate a similar deprecation notice, but for the `preg_match()` function. Fixed by using `array_filter()` on the attributes to explicitly filter out `null` values before passing the attributes to `Requests_Cookie`. Note: I'm choosing to explicitly only filter `null` values. Using `array_filter()` without a callback would filter out all "empty" values, but that may also remove values which are explicitly set to `false` or `0`, which may be valid values. Fixes two errors in the `external-http` group in the WordPress Core test suite: {{{ 1) Tests_HTTP_Functions::test_get_response_cookies_with_wp_http_cookie_object strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated /var/www/src/wp-includes/Requests/Cookie.php:268 /var/www/src/wp-includes/Requests/Cookie.php:237 /var/www/src/wp-includes/Requests/Cookie.php:90 /var/www/src/wp-includes/class-http.php:460 /var/www/src/wp-includes/class-http.php:349 /var/www/src/wp-includes/class-http.php:624 /var/www/src/wp-includes/http.php:162 /var/www/tests/phpunit/tests/http/functions.php:156 2) Tests_HTTP_Functions::test_get_cookie_host_only strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated /var/www/src/wp-includes/Requests/Cookie.php:268 /var/www/src/wp-includes/Requests/Cookie.php:237 /var/www/src/wp-includes/Requests/Cookie.php:90 /var/www/src/wp-includes/class-http.php:460 /var/www/tests/phpunit/tests/http/functions.php:235 }}} Follow-up to [38164], [45135], [51657]. Props jrf, hellofromTonya. See #53635. Built from https://develop.svn.wordpress.org/trunk@51801 git-svn-id: http://core.svn.wordpress.org/trunk@51408 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 8 +++++++- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 703a74e208..24b7724b89 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -459,7 +459,13 @@ class WP_Http { foreach ( $cookies as $name => $value ) { if ( $value instanceof WP_Http_Cookie ) { - $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes(), array( 'host-only' => $value->host_only ) ); + $attributes = array_filter( + $value->get_attributes(), + static function( $attr ) { + return null !== $attr; + } + ); + $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) ); } elseif ( is_scalar( $value ) ) { $cookie_jar[ $name ] = new Requests_Cookie( $name, $value ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 85d0e73278..a3f5c90e95 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51800'; +$wp_version = '5.9-alpha-51801'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.