8000 [HttpClient] Fix multidimensional array as body in copy as curl · symfony/symfony@d8c5f2d · GitHub
[go: up one dir, main page]

Skip to content

Commit d8c5f2d

Browse files
committed
[HttpClient] Fix multidimensional array as body in copy as curl
1 parent f1c0adb commit d8c5f2d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ private function getCurlCommand(array $trace): ?string
199199
if (\is_string($body)) {
200200
$dataArg[] = '--data '.escapeshellarg($body);
201201
} elseif (\is_array($body)) {
202-
foreach ($body as $key => $value) {
203-
$dataArg[] = '--data '.escapeshellarg("$key=$value");
202+
$body = explode('&', self::normalizeBody($body));
10000
203+
foreach ($body as $value) {
204+
$dataArg[] = '--data '.escapeshellarg(urldecode($value));
204205
}
205206
} else {
206207
return null;

src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ public function provideCurlRequests(): iterable
244244
'foo' => 'fooval',
245245
'bar' => 'barval',
246246
'baz' => 'bazval',
247+
'foobar' => [
248+
'baz' => 'bazval',
249+
'qux' => 'quxval',
250+
],
251+
'bazqux' => ['bazquxval1', 'bazquxval2'],
252+
'object' => (object) [
253+
'fooprop' => 'foopropval',
254+
'barprop' => 'barpropval',
255+
],
256+
'tostring' => new class() {
257+
public function __toString(): string
258+
{
259+
return 'tostringval';
260+
}
261+
},
247262
],
248263
],
249264
],
@@ -253,10 +268,10 @@ public function provideCurlRequests(): iterable
253268
--url %1$shttp://localhost:8057/json%1$s \\
254269
--header %1$sAccept: */*%1$s \\
255270
--header %1$sContent-Type: application/x-www-form-urlencoded%1$s \\
256-
--header %1$sContent-Length: 32%1$s \\
271+
--header %1$sContent-Length: 211%1$s \\
257272
--header %1$sAccept-Encoding: gzip%1$s \\
258273
--header %1$sUser-Agent: Symfony HttpClient/Native%1$s \\
259-
--data %1$sfoo=fooval%1$s --data %1$sbar=barval%1$s --data %1$sbaz=bazval%1$s',
274+
--data %1$sfoo=fooval%1$s --data %1$sbar=barval%1$s --data %1$sbaz=bazval%1$s --data %1$sfoobar[baz]=bazval%1$s --data %1$sfoobar[qux]=quxval%1$s --data %1$sbazqux[0]=bazquxval1%1$s --data %1$sbazqux[1]=bazquxval2%1$s --data %1$sobject[fooprop]=foopropval%1$s --data %1$sobject[barprop]=barpropval%1$s --data %1$stostring=tostringval%1$s',
260275
];
261276

262277
// escapeshellarg on Windows replaces double quotes & percent signs with spaces

0 commit comments

Comments
 (0)
0