File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
src/Symfony/Component/HttpClient Expand file tree Collapse file tree 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
194194 $ dataArg [] = '--data ' .escapeshellarg (json_encode ($ json , \JSON_PRETTY_PRINT ));
195195 } elseif ($ body = $ trace ['options ' ]['body ' ] ?? null ) {
196196 if (\is_string ($ body )) {
197- $ dataArg [] = '--data ' .escapeshellarg ($ body );
197+ try {
198+ $ dataArg [] = '--data ' .escapeshellarg ($ body );
199+ } catch (\ValueError $ e ) {
200+ return null ;
201+ }
198202 } elseif (\is_array ($ body )) {
199203 foreach ($ body as $ key => $ value ) {
200204 $ dataArg [] = '--data ' .escapeshellarg ("$ key= $ value " );
Original file line number Diff line number Diff line change @@ -343,6 +343,28 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
343343 self ::assertNull ($ curlCommand );
344344 }
345345
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+
346368 private function httpClientThatHasTracedRequests ($ tracedRequests ): TraceableHttpClient
347369 {
348370 $ httpClient = new TraceableHttpClient (new NativeHttpClient ());
You can’t perform that action at this time.
0 commit comments