Make WordPress Core

Changeset 52833


Ignore:
Timestamp:
03/09/2022 03:06:09 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Canonical: Check if the URL scheme exists in strip_fragment_from_url().

This avoids an "Undefined index" PHP notice when a schemeless URI is passed.

Props dd32, SergeyBiryukov.
Fixes #55333.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r51125 r52833  
    848848 */
    849849function strip_fragment_from_url( $url ) {
    850     $parsed_url = parse_url( $url );
     850    $parsed_url = wp_parse_url( $url );
    851851
    852852    if ( ! empty( $parsed_url['host'] ) ) {
    853         // This mirrors code in redirect_canonical(). It does not handle every case.
    854         $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
     853        $url = '';
     854
     855        if ( ! empty( $parsed_url['scheme'] ) ) {
     856            $url = $parsed_url['scheme'] . ':';
     857        }
     858
     859        $url .= '//' . $parsed_url['host'];
     860
    855861        if ( ! empty( $parsed_url['port'] ) ) {
    856862            $url .= ':' . $parsed_url['port'];
Note: See TracChangeset for help on using the changeset viewer.