file MDL-23075 fix format_postdata_for_curlcall when the params is an array of array of array
This commit is contained in:
+4
-3
@@ -926,11 +926,12 @@ function file_get_upload_error($errorcode) {
|
||||
*/
|
||||
function format_array_postdata_for_curlcall($arraydata, $currentdata, &$data) {
|
||||
foreach ($arraydata as $k=>$v) {
|
||||
$newcurrentdata = $currentdata;
|
||||
if (is_array($v)) { //the value is an array, call the function recursively
|
||||
$currentdata = $currentdata.'['.urlencode($k).']';
|
||||
format_array_postdata_for_curlcall($v, $currentdata, $data);
|
||||
$newcurrentdata = $newcurrentdata.'['.urlencode($k).']';
|
||||
format_array_postdata_for_curlcall($v, $newcurrentdata, $data);
|
||||
} else { //add the POST parameter to the $data array
|
||||
$data[] = $currentdata.'['.urlencode($k).']='.urlencode($v);
|
||||
$data[] = $newcurrentdata.'['.urlencode($k).']='.urlencode($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,15 @@ class filelib_test extends UnitTestCase {
|
||||
$postdata = format_postdata_for_curlcall($postdatatoconvert);
|
||||
$this->assertEqual($postdata, $expectedresult);
|
||||
|
||||
|
||||
|
||||
|
||||
//POST params with other complex types
|
||||
$postdatatoconvert = array ('members' =>
|
||||
array(
|
||||
array('groupid' => 1, 'userid' => 1)
|
||||
, array('groupid' => 1, 'userid' => 2)
|
||||
)
|
||||
);
|
||||
$expectedresult = "members[0][groupid]=1&members[0][userid]=1&members[1][groupid]=1&members[1][userid]=2";
|
||||
$postdata = format_postdata_for_curlcall($postdatatoconvert);
|
||||
$this->assertEqual($postdata, $expectedresult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user