From 749c06e91fa69187d2e4a1f9b4c51f8419026f59 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sun, 16 Sep 2012 16:16:26 +0000 Subject: [PATCH] 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 --- wp-includes/functions.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index d82bf97164..631be64dc1 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -655,9 +655,12 @@ function add_query_arg() { else $frag = ''; - if ( preg_match( '|^https?://|i', $uri, $matches ) ) { - $protocol = $matches[0]; - $uri = substr( $uri, strlen( $protocol ) ); + if ( 0 === stripos( 'http://', $uri ) ) { + $protocol = 'http://'; + $uri = substr( $uri, 7 ); + } elseif ( 0 === stripos( 'https://', $uri ) ) { + $protocol = 'https://'; + $uri = substr( $uri, 8 ); } else { $protocol = ''; } @@ -671,7 +674,7 @@ function add_query_arg() { $base = $parts[0] . '?'; $query = $parts[1]; } - } elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { + } elseif ( $protocol || strpos( $uri, '=' ) === false ) { $base = $uri . '?'; $query = ''; } else { @@ -688,7 +691,7 @@ function add_query_arg() { $qs[ $args[0] ] = $args[1]; } - foreach ( (array) $qs as $k => $v ) { + foreach ( $qs as $k => $v ) { if ( $v === false ) unset( $qs[$k] ); }