mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-14 22:56:19 +01:00
Only urlencode previously existing values in add_query_arg() (more backwards compatible). fixes #4935. see #4084. see #4878
git-svn-id: http://svn.automattic.com/wordpress/trunk@6064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
23b1e871a1
commit
79c4324e01
@ -105,24 +105,33 @@ if (!function_exists('http_build_query')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
|
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
|
||||||
function _http_build_query($data, $prefix=null, $sep=null, $key='') {
|
function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
if ( $urlencode ) {
|
||||||
|
$lsb = '%5B';
|
||||||
|
$rsb = '%5D';
|
||||||
|
} else {
|
||||||
|
$lsb = '[';
|
||||||
|
$rsb = ']';
|
||||||
|
}
|
||||||
foreach ( (array) $data as $k => $v ) {
|
foreach ( (array) $data as $k => $v ) {
|
||||||
|
if ( $urlencode)
|
||||||
$k = urlencode($k);
|
$k = urlencode($k);
|
||||||
if ( is_int($k) && $prefix != null )
|
if ( is_int($k) && $prefix != null )
|
||||||
$k = $prefix.$k;
|
$k = $prefix.$k;
|
||||||
if ( !empty($key) )
|
if ( !empty($key) )
|
||||||
$k = $key . '%5B' . $k . '%5D';
|
$k = $key . '%5B' . $k . '%5D';
|
||||||
|
|
||||||
if ( $v === NULL )
|
if ( $v === NULL )
|
||||||
continue;
|
continue;
|
||||||
elseif ( $v === FALSE )
|
elseif ( $v === FALSE )
|
||||||
$v = '0';
|
$v = '0';
|
||||||
|
|
||||||
if ( is_array($v) || is_object($v) )
|
if ( is_array($v) || is_object($v) )
|
||||||
array_push($ret,_http_build_query($v, '', $sep, $k));
|
array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
|
||||||
else
|
elseif ( $urlencode )
|
||||||
array_push($ret, $k.'='.urlencode($v));
|
array_push($ret, $k.'='.urlencode($v));
|
||||||
|
else
|
||||||
|
array_push($ret, $k.'='.$v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( NULL === $sep )
|
if ( NULL === $sep )
|
||||||
|
@ -581,6 +581,10 @@ function is_new_day() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function build_query($data) {
|
||||||
|
return _http_build_query($data, NULL, '&', '', false);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
add_query_arg: Returns a modified querystring by adding
|
add_query_arg: Returns a modified querystring by adding
|
||||||
a single key & value or an associative array.
|
a single key & value or an associative array.
|
||||||
@ -635,6 +639,7 @@ function add_query_arg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wp_parse_str($query, $qs);
|
wp_parse_str($query, $qs);
|
||||||
|
$qs = urlencode_deep($qs); // this re-URL-encodes things that were already in the query string
|
||||||
if ( is_array(func_get_arg(0)) ) {
|
if ( is_array(func_get_arg(0)) ) {
|
||||||
$kayvees = func_get_arg(0);
|
$kayvees = func_get_arg(0);
|
||||||
$qs = array_merge($qs, $kayvees);
|
$qs = array_merge($qs, $kayvees);
|
||||||
@ -647,10 +652,7 @@ function add_query_arg() {
|
|||||||
unset($qs[$k]);
|
unset($qs[$k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ini_get('arg_separator.output') === '&')
|
$ret = build_query($qs);
|
||||||
$ret = http_build_query($qs, '', '&');
|
|
||||||
else
|
|
||||||
$ret = _http_build_query($qs, NULL, '&');
|
|
||||||
$ret = trim($ret, '?');
|
$ret = trim($ret, '?');
|
||||||
$ret = preg_replace('#=(&|$)#', '$1', $ret);
|
$ret = preg_replace('#=(&|$)#', '$1', $ret);
|
||||||
$ret = $protocol . $base . $ret . $frag;
|
$ret = $protocol . $base . $ret . $frag;
|
||||||
|
Loading…
Reference in New Issue
Block a user