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
This commit is contained in:
johnjamesjacoby
2025-07-22 16:25:31 +00:00
parent b9059ad4fe
commit f70e032c5f
2 changed files with 9 additions and 1 deletions

View File

@@ -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'] );

View File

@@ -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.