WordPress.org

Make WordPress Core

Changeset 6064


Ignore:
Timestamp:
09/08/07 14:27:24 (7 years ago)
Author:
markjaquith
Message:

Only urlencode previously existing values in add_query_arg() (more backwards compatible). fixes #4935. see #4084. see #4878

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/compat.php

    r5999 r6064  
    106106 
    107107// from php.net (modified by Mark Jaquith to behave like the native PHP5 function) 
    108 function _http_build_query($data, $prefix=null, $sep=null, $key='') { 
     108function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { 
    109109    $ret = array(); 
     110    if ( $urlencode ) { 
     111        $lsb = '%5B'; 
     112        $rsb = '%5D'; 
     113    } else { 
     114        $lsb = '['; 
     115        $rsb = ']'; 
     116    } 
    110117    foreach ( (array) $data as $k => $v ) { 
    111         $k = urlencode($k); 
     118        if ( $urlencode) 
     119            $k = urlencode($k); 
    112120        if ( is_int($k) && $prefix != null ) 
    113121            $k = $prefix.$k; 
    114122        if ( !empty($key) ) 
    115123            $k = $key . '%5B' . $k . '%5D'; 
    116  
    117124        if ( $v === NULL ) 
    118125            continue; 
     
    121128 
    122129        if ( is_array($v) || is_object($v) ) 
    123             array_push($ret,_http_build_query($v, '', $sep, $k)); 
     130            array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); 
     131        elseif ( $urlencode ) 
     132            array_push($ret, $k.'='.urlencode($v)); 
    124133        else 
    125             array_push($ret, $k.'='.urlencode($v)); 
    126         } 
     134            array_push($ret, $k.'='.$v); 
     135    } 
    127136 
    128137    if ( NULL === $sep ) 
  • trunk/wp-includes/functions.php

    r6057 r6064  
    582582} 
    583583 
     584function build_query($data) { 
     585    return _http_build_query($data, NULL, '&', '', false); 
     586} 
     587 
    584588/* 
    585589add_query_arg: Returns a modified querystring by adding 
     
    636640 
    637641    wp_parse_str($query, $qs); 
     642    $qs = urlencode_deep($qs); // this re-URL-encodes things that were already in the query string 
    638643    if ( is_array(func_get_arg(0)) ) { 
    639644        $kayvees = func_get_arg(0); 
     
    648653    } 
    649654 
    650     if ( ini_get('arg_separator.output') === '&') 
    651         $ret = http_build_query($qs, '', '&'); 
    652     else 
    653         $ret = _http_build_query($qs, NULL, '&'); 
     655    $ret = build_query($qs); 
    654656    $ret = trim($ret, '?'); 
    655657    $ret = preg_replace('#=(&|$)#', '$1', $ret); 
Note: See TracChangeset for help on using the changeset viewer.