From 9ea3f9f676ec554f309df66d9c6591a53c0f53ae Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 4 Dec 2015 23:11:26 +0000 Subject: [PATCH] Canonical: introduce `strip_fragment_from_url()` and use when comparing URLs in `redirect_canonical()`. Props tellyworth. Fixes #19918. Built from https://develop.svn.wordpress.org/trunk@35770 git-svn-id: http://core.svn.wordpress.org/trunk@35734 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 27 ++++++++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 84b90e279e..cacbdaadfe 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -489,7 +489,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url ); // yes, again -- in case the filter aborted the request - if ( ! $redirect_url || $redirect_url == $requested_url ) { + if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) { return; } @@ -534,6 +534,31 @@ function _remove_qs_args_if_not_in_url( $query_string, Array $args_to_check, $ur return $query_string; } +/** + * Strips the #fragment from a URL, if one is present. + * + * @since 4.4.0 + * + * @param string $url The URL to strip. + * @return string The altered URL. + */ +function strip_fragment_from_url( $url ) { + $parsed_url = @parse_url( $url ); + if ( ! empty( $parsed_url['host'] ) ) { + // This mirrors code in redirect_canonical(). It does not handle every case. + $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; + if ( ! empty( $parsed_url['port'] ) ) { + $url .= ':' . $parsed_url['port']; + } + $url .= $parsed_url['path']; + if ( ! empty( $parsed_url['query'] ) ) { + $url .= '?' . $parsed_url['query']; + } + } + + return $url; +} + /** * Attempts to guess the correct URL based on query vars * diff --git a/wp-includes/version.php b/wp-includes/version.php index 4f6ac7e674..6f342bc024 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-RC1-35769'; +$wp_version = '4.4-RC1-35770'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.