file MDL-23075 fix format_postdata_for_curlcall when the params is an array of array of array

This commit is contained in:
jerome mouneyrac
2010-07-05 02:56:04 +00:00
parent 4cec22dce6
commit 277c7a4033
2 changed files with 14 additions and 6 deletions
+4 -3
View File
@@ -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);
}
}
}
+10 -3
View File
@@ -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);
}
}