WordPress.org

Make WordPress Core

Ticket #19918: 19918.2.diff

File 19918.2.diff, 1.3 KB (added by wonderboymusic, 4 years ago)
  • src/wp-includes/canonical.php

     
    489489        $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );
    490490
    491491        // yes, again -- in case the filter aborted the request
    492         if ( ! $redirect_url || $redirect_url == $requested_url ) {
     492        if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
    493493                return;
    494494        }
    495495
     
    535535}
    536536
    537537/**
     538 * Strips the #fragment from a URL, if one is present.
     539 *
     540 * @param string $url The URL to strip.
     541 * @return string The altered URL.
     542 */
     543function strip_fragment_from_url( $url ) {
     544        $parsed_url = @parse_url( $url );
     545        if ( ! empty( $parsed_url['host'] ) ) {
     546                // This mirrors code in redirect_canonical(). It does not handle every case.
     547                $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
     548                if ( ! empty( $parsed_url['port'] ) ) {
     549                        $url .= ':' . $parsed_url['port'];
     550                }
     551                $url .= $parsed_url['path'];
     552                if ( ! empty( $parsed_url['query'] ) ) {
     553                        $url .= '?' . $parsed_url['query'];
     554                }
     555        }
     556
     557        return $url;
     558}
     559
     560/**
    538561 * Attempts to guess the correct URL based on query vars
    539562 *
    540563 * @since 2.3.0