Skip to content

Commit fa40d08

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60496 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8a3c793 commit fa40d08

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/wp-includes/canonical.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,14 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
615615
unset( $redirect['port'] );
616616
}
617617

618+
// Notice prevention after new parse_url( $redirect_url ) calls
619+
if ( ! isset( $redirect['path'] ) ) {
620+
$redirect['path'] = '';
621+
}
622+
if ( ! isset( $redirect['query'] ) ) {
623+
$redirect['query'] = '';
624+
}
625+
618626
// Trailing /index.php.
619627
$redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path'] );
620628

0 commit comments

Comments
 (0)