File tree 2 files changed +27
-1
lines changed
src/Symfony/Component/HttpClient
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -194,7 +194,11 @@ private function getCurlCommand(array $trace): ?string
194
194
$ dataArg [] = '--data ' .escapeshellarg (json_encode ($ json , \JSON_PRETTY_PRINT ));
195
195
} elseif ($ body = $ trace ['options ' ]['body ' ] ?? null ) {
196
196
if (\is_string ($ body )) {
197
- $ dataArg [] = '--data ' .escapeshellarg ($ body );
197
+ try {
198
+ $ dataArg [] = '--data ' .escapeshellarg ($ body );
199
+ } catch (\ValueError $ e ) {
200
+ return null ;
201
+ }
198
202
} elseif (\is_array ($ body )) {
199
203
foreach ($ body as $ key => $ value ) {
200
204
$ dataArg [] = '--data ' .escapeshellarg ("$ key= $ value " );
Original file line number Diff line number Diff line change @@ -343,6 +343,28 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
343
343
self ::assertNull ($ curlCommand );
344
344
}
345
345
346
+ /**
347
+ * @requires extension openssl
348
+ */
349
+ public function testItDoesNotGeneratesCurlCommandsForNotEncodableBody ()
350
+ {
351
+ $ sut = new HttpClientDataCollector ();
352
+ $ sut ->registerClient ('http_client ' , $ this ->httpClientThatHasTracedRequests ([
353
+ [
354
+ 'method ' => 'POST ' ,
355
+ 'url ' => 'http://localhost:8057/json ' ,
356
+ 'options ' => [
357
+ 'body ' => "\0" ,
358
+ ],
359
+ ],
360
+ ]));
361
+ $ sut ->collect (new Request (), new Response ());
362
+ $ collectedData = $ sut ->getClients ();
363
+ self ::assertCount (1 , $ collectedData ['http_client ' ]['traces ' ]);
364
+ $ curlCommand = $ collectedData ['http_client ' ]['traces ' ][0 ]['curlCommand ' ];
365
+ self ::assertNull ($ curlCommand );
366
+ }
367
+
346
368
private function httpClientThatHasTracedRequests ($ tracedRequests ): TraceableHttpClient
347
369
{
348
370
$ httpClient = new TraceableHttpClient (new NativeHttpClient ());
You can’t perform that action at this time.
0 commit comments