From f70e032c5f1e38abdbefe993bf21732a29ac1608 Mon Sep 17 00:00:00 2001 From: johnjamesjacoby Date: Tue, 22 Jul 2025 16:25:31 +0000 Subject: [PATCH] Canonical: prevent possible "Undefined array key" PHP error in `redirect_canonical()`, if the `path` or `query` array keys have gone missing. This commit checks for the existence of (and re-adds if necessary) the `path` and `query` array keys after the `$redirect` variable has potentially been replaced by a second call to `parse_url()`. This may happen when redirecting back to the root domain, without any path ('/example/`) or query (`?example=1`) to parse. Props chrismattix, dhruvang21. Fixes #63733. Built from https://develop.svn.wordpress.org/trunk@60496 git-svn-id: http://core.svn.wordpress.org/trunk@59832 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 58723ebc0d..a9570a1bdd 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -615,6 +615,14 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { unset( $redirect['port'] ); } + // Notice prevention after new parse_url( $redirect_url ) calls + if ( ! isset( $redirect['path'] ) ) { + $redirect['path'] = ''; + } + if ( ! isset( $redirect['query'] ) ) { + $redirect['query'] = ''; + } + // Trailing /index.php. $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path'] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 48edefb44b..23d9f43069 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-alpha-60495'; +$wp_version = '6.9-alpha-60496'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.