diff --git a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php index 292cdf3945bcf..9c92db2cc5582 100644 --- a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php +++ b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php @@ -194,7 +194,11 @@ private function getCurlCommand(array $trace): ?string $dataArg[] = '--data '.escapeshellarg(json_encode($json, \JSON_PRETTY_PRINT)); } elseif ($body = $trace['options']['body'] ?? null) { if (\is_string($body)) { - $dataArg[] = '--data '.escapeshellarg($body); + try { + $dataArg[] = '--data '.escapeshellarg($body); + } catch (\ValueError $e) { + return null; + } } elseif (\is_array($body)) { foreach ($body as $key => $value) { $dataArg[] = '--data '.escapeshellarg("$key=$value"); diff --git a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php index ebe4c2c52569b..37bba8c79aac2 100755 --- a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php +++ b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php @@ -343,6 +343,28 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType() self::assertNull($curlCommand); } + /** + * @requires extension openssl + */ + public function testItDoesNotGeneratesCurlCommandsForNotEncodableBody() + { + $sut = new HttpClientDataCollector(); + $sut->registerClient('http_client', $this->httpClientThatHasTracedRequests([ + [ + 'method' => 'POST', + 'url' => 'http://localhost:8057/json', + 'options' => [ + 'body' => "\0", + ], + ], + ])); + $sut->collect(new Request(), new Response()); + $collectedData = $sut->getClients(); + self::assertCount(1, $collectedData['http_client']['traces']); + $curlCommand = $collectedData['http_client']['traces'][0]['curlCommand']; + self::assertNull($curlCommand); + } + private function httpClientThatHasTracedRequests($tracedRequests): TraceableHttpClient { $httpClient = new TraceableHttpClient(new NativeHttpClient()); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy