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

Skip to content

Commit 0a6bd94

Browse files
committed
[HttpClient] Fix multidimensional array as body in copy as curl
1 parent a36161b commit 0a6bd94

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));
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
@@ -267,6 +267,21 @@ public function provideCurlRequests(): iterable
267267
'foo' => 'fooval',
268268
'bar' => 'barval',
269269
'baz' => 'bazval',
270+
'foobar' => [
271+
'baz' => 'bazval',
272+
'qux' => 'quxval',
273+
],
274+
'bazqux' => ['bazquxval1', 'bazquxval2'],
275+
'object' => (object) [
276+
'fooprop' => 'foopropval',
277+
'barprop' => 'barpropval',
278+
],
279+
'tostring' => new class() {
280+
public function __toString(): string
281+
{
282+
return 'tostringval';
283+
}
284+
},
270285
],
271286
],
272287
],
@@ -276,10 +291,10 @@ public function provideCurlRequests(): iterable
276291
--url %1$shttp://localhost:8057/json%1$s \\
277292
--header %1$sAccept: */*%1$s \\
278293
--header %1$sContent-Type: application/x-www-form-urlencoded%1$s \\
279-
--header %1$sContent-Length: 32%1$s \\
294+
--header %1$sContent-Length: 211%1$s \\
280295
--header %1$sAccept-Encoding: gzip%1$s \\
281296
--header %1$sUser-Agent: Symfony HttpClient/Native%1$s \\
282-
--data %1$sfoo=fooval%1$s --data %1$sbar=barval%1$s --data %1$sbaz=bazval%1$s',
297+
--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',
283298
];
284299

285300
// escapeshellarg on Windows replaces double quotes with spaces

0 commit comments

Comments
 (0)
0