Better protocol validation in set_url_scheme().

Built from https://develop.svn.wordpress.org/trunk@25319


git-svn-id: http://core.svn.wordpress.org/trunk@25281 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-09-10 18:08:11 +00:00
parent cf3fddde96
commit 3e41af8489
1 changed files with 11 additions and 4 deletions

View File

@ -2240,10 +2240,17 @@ function set_url_scheme( $url, $scheme = null ) {
$scheme = ( is_ssl() ? 'https' : 'http' );
}
if ( 'relative' == $scheme )
$url = preg_replace( '#^.+://[^/]*#', '', $url );
else
$url = preg_replace( '#^.+://#', $scheme . '://', $url );
$url = trim( $url );
if ( $url[0] === '/' && $url[1] === '/' )
$url = 'http:' . $url;
if ( 'relative' == $scheme ) {
$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
if ( $url[0] === '/' )
$url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
} else {
$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
}
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
}