Skip to content

Commit 584ecf9

Browse files
committed
Add test for nested arrays in data (php-curl-class#8)
1 parent 5acdd24 commit 584ecf9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Curl.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private function http_build_multi_query($data, $key=NULL) {
114114
$query[] = urlencode(is_null($key) ? $k : $key . $brackets) . '=' . rawurlencode($value);
115115
}
116116
else if (is_array($value)) {
117-
$nested = (is_null($key)) ? $k : $key . '[' . $k . ']';
117+
$nested = is_null($key) ? $k : $key . '[' . $k . ']';
118118
$query[] = $this->http_build_multi_query($value, $nested);
119119
}
120120
}

tests/run.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,23 @@ public function testRequestURL() {
201201
$test = new Test();
202202
$this->assertFalse(substr($test->server('request_uri', 'DELETE'), -1) === '?');
203203
}
204+
205+
public function testNestedData() {
206+
$test = new Test();
207+
$data = array(
208+
'username' => 'myusername',
209+
'password' => 'mypassword',
210+
'more_data' => array(
211+
'param1' => 'something',
212+
'param2' => 'other thing',
213+
'another' => array(
214+
'extra' => 'level',
215+
'because' => 'I need it',
216+
),
217+
),
218+
);
219+
$this->assertTrue(
220+
$test->server('post', 'POST', $data) === http_build_query($data)
221+
);
222+
}
204223
}

0 commit comments

Comments
 (0)