From 6ec2594d74fb25140917d8caf41c259498fa43c4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 17 Aug 2021 22:07:55 +0000 Subject: [PATCH] Code Modernization: Check the return type of `parse_url()` in `ms_cookie_constants()`. As per the PHP manual: > If the `component` parameter is omitted, an associative array is returned. > If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned. Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values] It is entirely possible for the `siteurl` option to not have a "path" component. In PHP 8.1, this would lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice. Changing the logic around and adding validation for the return type value of `parse_url()` prevents that. As this function is declaring global constants, adding tests for this change is not really an option without potentially affecting other tests. Follow-up to [51606], [51622], [51626], [51629]. Props jrf, hellofromTonya, SergeyBiryukov. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51630 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-default-constants.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/ms-default-constants.php b/src/wp-includes/ms-default-constants.php index 7d794e32e6..016ed437b7 100644 --- a/src/wp-includes/ms-default-constants.php +++ b/src/wp-includes/ms-default-constants.php @@ -68,7 +68,8 @@ function ms_cookie_constants() { * @since 2.6.0 */ if ( ! defined( 'ADMIN_COOKIE_PATH' ) ) { - if ( ! is_subdomain_install() || trim( parse_url( get_option( 'siteurl' ), PHP_URL_PATH ), '/' ) ) { + $site_path = parse_url( get_option( 'siteurl' ), PHP_URL_PATH ); + if ( ! is_subdomain_install() || is_string( $site_path ) && trim( $site_path, '/' ) ) { define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH ); } else { define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );