Make WordPress Core

Changeset 60496

Timestamp:
07/22/2025 04:23:35 PM (3 months ago)
Author:
johnjamesjacoby
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r58924 r60496  
    614614    } else {
    615615        unset( $redirect['port'] );
     616    }
     617
     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'] = '';
    616624    }
    617625
Note: See TracChangeset for help on using the changeset viewer.