Simplify protocol stripping in add_query_arg() by avoiding a regular expression. Don't cast a known array to an array. fixes #21332.

git-svn-id: http://core.svn.wordpress.org/trunk@21865 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-09-16 16:16:26 +00:00
parent e914a04335
commit 749c06e91f
1 changed files with 8 additions and 5 deletions

View File

@ -655,9 +655,12 @@ function add_query_arg() {
else else
$frag = ''; $frag = '';
if ( preg_match( '|^https?://|i', $uri, $matches ) ) { if ( 0 === stripos( 'http://', $uri ) ) {
$protocol = $matches[0]; $protocol = 'http://';
$uri = substr( $uri, strlen( $protocol ) ); $uri = substr( $uri, 7 );
} elseif ( 0 === stripos( 'https://', $uri ) ) {
$protocol = 'https://';
$uri = substr( $uri, 8 );
} else { } else {
$protocol = ''; $protocol = '';
} }
@ -671,7 +674,7 @@ function add_query_arg() {
$base = $parts[0] . '?'; $base = $parts[0] . '?';
$query = $parts[1]; $query = $parts[1];
} }
} elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { } elseif ( $protocol || strpos( $uri, '=' ) === false ) {
$base = $uri . '?'; $base = $uri . '?';
$query = ''; $query = '';
} else { } else {
@ -688,7 +691,7 @@ function add_query_arg() {
$qs[ $args[0] ] = $args[1]; $qs[ $args[0] ] = $args[1];
} }
foreach ( (array) $qs as $k => $v ) { foreach ( $qs as $k => $v ) {
if ( $v === false ) if ( $v === false )
unset( $qs[$k] ); unset( $qs[$k] );
} }