Skip to content

Commit 2e2dff5

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Serializer] Fix `@method` annotation fix compatibility with Doctrine DBAL 4 ensure string type with mbstring func overloading enabled [HttpKernel] Fix quotes expectations in tests [Validator] updated Greek translation [Cache][HttpFoundation][Lock] Fix empty username/password for PDO PostgreSQL [HttpClient][WebProfilerBundle] Do not generate cURL command when files are uploaded
2 parents 302c656 + 0314e2d commit 2e2dff5

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

DataCollector/HttpClientDataCollector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpClient\DataCollector;
1313

14+
use Symfony\Component\HttpClient\Exception\TransportException;
1415
use Symfony\Component\HttpClient\HttpClientTrait;
1516
use Symfony\Component\HttpClient\TraceableHttpClient;
1617
use Symfony\Component\HttpFoundation\Request;
@@ -199,7 +200,11 @@ private function getCurlCommand(array $trace): ?string
199200
if (\is_string($body)) {
200201
$dataArg[] = '--data-raw '.$this->escapePayload($body);
201202
} elseif (\is_array($body)) {
202-
$body = explode('&', self::normalizeBody($body));
203+
try {
204+
$body = explode('&', self::normalizeBody($body));
205+
} catch (TransportException) {
206+
return null;
207+
}
203208
foreach ($body as $value) {
204209
$dataArg[] = '--data-raw '.$this->escapePayload(urldecode($value));
205210
}

Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ public function testItIsEmptyAfterReset()
165165
}
166166

167167
/**
168-
* @requires extension openssl
169-
*
170168
* @dataProvider provideCurlRequests
171169
*/
172170
public function testItGeneratesCurlCommandsAsExpected(array $request, string $expectedCurlCommand)
@@ -177,7 +175,9 @@ public function testItGeneratesCurlCommandsAsExpected(array $request, string $ex
177175
$collectedData = $sut->getClients();
178176
self::assertCount(1, $collectedData['http_client']['traces']);
179177
$curlCommand = $collectedData['http_client']['traces'][0]['curlCommand'];
180-
self::assertEquals(sprintf($expectedCurlCommand, '\\' === \DIRECTORY_SEPARATOR ? '"' : "'"), $curlCommand);
178+
179+
$isWindows = '\\' === \DIRECTORY_SEPARATOR;
180+
self::assertEquals(sprintf($expectedCurlCommand, $isWindows ? '"' : "'", $isWindows ? '' : "'"), $curlCommand);
181181
}
182182

183183
public static function provideCurlRequests(): iterable
@@ -236,19 +236,19 @@ public static function provideCurlRequests(): iterable
236236
'method' => 'POST',
237237
'url' => 'http://localhost:8057/json',
238238
'options' => [
239-
'body' => 'foobarbaz',
239+
'body' => 'foo bar baz',
240240
],
241241
],
242242
'curl \\
243243
--compressed \\
244244
--request POST \\
245245
--url %1$shttp://localhost:8057/json%1$s \\
246246
--header %1$sAccept: */*%1$s \\
247-
--header %1$sContent-Length: 9%1$s \\
247+
--header %1$sContent-Length: 11%1$s \\
248248
--header %1$sContent-Type: application/x-www-form-urlencoded%1$s \\
249249
--header %1$sAccept-Encoding: gzip%1$s \\
250250
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s \\
251-
--data-raw %1$sfoobarbaz%1$s',
251+
--data-raw %1$sfoo bar baz%1$s',
252252
];
253253
yield 'POST with array body' => [
254254
[
@@ -286,7 +286,7 @@ public function __toString(): string
286286
--header %1$sContent-Length: 211%1$s \\
287287
--header %1$sAccept-Encoding: gzip%1$s \\
288288
--header %1$sUser-Agent: Symfony HttpClient (Native)%1$s \\
289-
--data-raw %1$sfoo=fooval%1$s --data-raw %1$sbar=barval%1$s --data-raw %1$sbaz=bazval%1$s --data-raw %1$sfoobar[baz]=bazval%1$s --data-raw %1$sfoobar[qux]=quxval%1$s --data-raw %1$sbazqux[0]=bazquxval1%1$s --data-raw %1$sbazqux[1]=bazquxval2%1$s --data-raw %1$sobject[fooprop]=foopropval%1$s --data-raw %1$sobject[barprop]=barpropval%1$s --data-raw %1$stostring=tostringval%1$s',
289+
--data-raw %2$sfoo=fooval%2$s --data-raw %2$sbar=barval%2$s --data-raw %2$sbaz=bazval%2$s --data-raw %2$sfoobar[baz]=bazval%2$s --data-raw %2$sfoobar[qux]=quxval%2$s --data-raw %2$sbazqux[0]=bazquxval1%2$s --data-raw %2$sbazqux[1]=bazquxval2%2$s --data-raw %2$sobject[fooprop]=foopropval%2$s --data-raw %2$sobject[barprop]=barpropval%2$s --data-raw %2$stostring=tostringval%2$s',
290290
];
291291

292292
// escapeshellarg on Windows replaces double quotes & percent signs with spaces
@@ -342,9 +342,6 @@ public function __toString(): string
342342
}
343343
}
344344

345-
/**
346-
* @requires extension openssl
347-
*/
348345
public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
349346
{
350347
$sut = new HttpClientDataCollector();
@@ -372,9 +369,6 @@ public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
372369
);
373370
}
374371

375-
/**
376-
* @requires extension openssl
377-
*/
378372
public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
379373
{
380374
$sut = new HttpClientDataCollector();
@@ -394,9 +388,6 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
394388
self::assertNull($curlCommand);
395389
}
396390

397-
/**
398-
* @requires extension openssl
399-
*/
400391
public function testItDoesGenerateCurlCommandsForBigData()
401392
{
402393
$sut = new HttpClientDataCollector();
@@ -416,6 +407,25 @@ public function testItDoesGenerateCurlCommandsForBigData()
416407
self::assertNotNull($curlCommand);
417408
}
418409

410+
public function testItDoesNotGeneratesCurlCommandsForUploadedFiles()
411+
{
412+
$sut = new HttpClientDataCollector();
413+
$sut->registerClient('http_client', $this->httpClientThatHasTracedRequests([
414+
[
415+
'method' => 'POST',
416+
'url' => 'http://localhost:8057/json',
417+
'options' => [
418+
'body' => ['file' => fopen('data://text/plain,', 'r')],
419+
],
420+
],
421+
]));
422+
$sut->lateCollect();
423+
$collectedData = $sut->getClients();
424+
self::assertCount(1, $collectedData['http_client']['traces']);
425+
$curlCommand = $collectedData['http_client']['traces'][0]['curlCommand'];
426+
self::assertNull($curlCommand);
427+
}
428+
419429
private function httpClientThatHasTracedRequests($tracedRequests): TraceableHttpClient
420430
{
421431
$httpClient = new TraceableHttpClient(new NativeHttpClient());

0 commit comments

Comments
 (0)