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.
Built from https://develop.svn.wordpress.org/trunk@52833


git-svn-id: http://core.svn.wordpress.org/trunk@52422 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-03-09 15:08:06 +00:00
parent a793be201b
commit a1d974a2e1
2 changed files with 10 additions and 4 deletions

View File

@ -847,11 +847,17 @@ function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $ur
* @return string The altered URL.
*/
function strip_fragment_from_url( $url ) {
$parsed_url = parse_url( $url );
$parsed_url = wp_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'];
$url = '';
if ( ! empty( $parsed_url['scheme'] ) ) {
$url = $parsed_url['scheme'] . ':';
}
$url .= '//' . $parsed_url['host'];
if ( ! empty( $parsed_url['port'] ) ) {
$url .= ':' . $parsed_url['port'];
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52832';
$wp_version = '6.0-alpha-52833';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.