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
This commit is contained in:
Scott Taylor 2015-12-04 23:11:26 +00:00
parent ef1280f770
commit 9ea3f9f676
2 changed files with 27 additions and 2 deletions

View File

@ -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
*

View File

@ -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.