Merge pull request #943 from jeffchan/fix-arraywalk
Fix PMA_arrayWalkRecursive to ensure single pass thru keys
This commit is contained in:
commit
938ba599a5
@ -442,11 +442,16 @@ function PMA_arrayMergeRecursive()
|
||||
*/
|
||||
function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false)
|
||||
{
|
||||
static $walked_keys = array();
|
||||
static $recursive_counter = 0;
|
||||
if (++$recursive_counter > 1000) {
|
||||
PMA_fatalError(__('possible deep recursion attack'));
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
if (isset($walked_keys[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
PMA_arrayWalkRecursive($array[$key], $function, $apply_to_keys_also);
|
||||
} else {
|
||||
@ -458,6 +463,9 @@ function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false)
|
||||
if ($new_key != $key) {
|
||||
$array[$new_key] = $array[$key];
|
||||
unset($array[$key]);
|
||||
$walked_keys[$new_key] = true;
|
||||
} else {
|
||||
$walked_keys[$key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,8 +369,8 @@ class PMA_Array_Test extends PHPUnit_Framework_TestCase
|
||||
'key3'=>'val3'
|
||||
);
|
||||
$target = array(
|
||||
"key1"=>'val1',
|
||||
'key2'=>array('skey1'=>'sval1', 'skey2'=>'sval2'),
|
||||
"key1"=>'v\\al1',
|
||||
'key2'=>array('s\\key1'=>'sval1', 'skey2'=>'sval2'),
|
||||
'key3'=>'val3'
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user