Skip to content

Commit cdac81d

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Fix merge Fix merge [FrameworkBundle] Improve error message in MicroKernelTrait when using deprecated configureRoutes(RouteCollectionBuilder) with symfony/routing >= 6.0 Add warning about Symfony 5.2 changing pcntl_async_signals [Tests] Fix static calls and Mock var annotation [FrameworkBundle] Fix checkboxes check assertions [Notifier][WebProfilerBundle] Ignore messages whose `getNotification` returns `null` [HttpClient] Fix over-encoding of URL parts to match browser's behavior Fix Psalm job Revert "[HttpClient] Add support for "friendsofphp/well-known-implementations"" [HttpClient] Fix data collector [Tests] Migrate tests to static data providers [Semaphore] Fix test Fix: Split and clean up tests Remove unused data provider [Form] Check for `RepeatedType` child in `PasswordHasherListener` add Sender to the list of bypassed headers
2 parents 67a395b + 0c2e735 commit cdac81d

File tree

7 files changed

+41
-36
lines changed

7 files changed

+41
-36
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ CHANGELOG
77
* Make `HttplugClient` implement `Psr\Http\Message\RequestFactoryInterface`, `StreamFactoryInterface` and `UriFactoryInterface`
88
* Deprecate implementing `Http\Message\RequestFactory`, `StreamFactory` and `UriFactory` on `HttplugClient`
99
* Add `withOptions()` to `HttplugClient` and `Psr18Client`
10-
* Add support for "friendsofphp/well-known-implementations"
1110

1211
6.1
1312
---

DataCollector/HttpClientDataCollector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function collect(Request $request, Response $response, \Throwable $except
4343

4444
public function lateCollect()
4545
{
46-
$this->data['request_count'] = 0;
47-
$this->data['error_count'] = 0;
46+
$this->data['request_count'] = $this->data['request_count'] ?? 0;
47+
$this->data['error_count'] = $this->data['error_count'] ?? 0;
4848
$this->data += ['clients' => []];
4949

5050
foreach ($this->clients as $name => $client) {
@@ -59,7 +59,8 @@ public function lateCollect()
5959

6060
$this->data['clients'][$name]['traces'] = array_merge($this->data['clients'][$name]['traces'], $traces);
6161
$this->data['request_count'] += \count($traces);
62-
$this->data['error_count'] += $this->data['clients'][$name]['error_count'] += $errorCount;
62+
$this->data['error_count'] += $errorCount;
63+
$this->data['clients'][$name]['error_count'] += $errorCount;
6364

6465
$client->reset();
6566
}

HttpClientTrait.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS
538538
}
539539

540540
// https://tools.ietf.org/html/rfc3986#section-3.3
541-
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()*+,;=:@%]++#", fn ($m) => rawurlencode($m[0]), $parts[$part]);
541+
$parts[$part] = preg_replace_callback("#[^-A-Za-z0-9._~!$&/'()[\]*+,;=:@\\\\^`{|}%]++#", fn ($m) => rawurlencode($m[0]), $parts[$part]);
542542
}
543543

544544
return [
@@ -612,6 +612,31 @@ private static function mergeQueryString(?string $queryString, array $queryArray
612612
$queryArray = [];
613613

614614
if ($queryString) {
615+
if (str_contains($queryString, '%')) {
616+
// https://tools.ietf.org/html/rfc3986#section-2.3 + some chars not encoded by browsers
617+
$queryString = strtr($queryString, [
618+
'%21' => '!',
619+
'%24' => '$',
620+
'%28' => '(',
621+
'%29' => ')',
622+
'%2A' => '*',
623+
'%2B' => '+',
624+
'%2C' => ',',
625+
'%2F' => '/',
626+
'%3A' => ':',
627+
'%3B' => ';',
628+
'%40' => '@',
629+
'%5B' => '[',
630+
'%5C' => '\\',
631+
'%5D' => ']',
632+
'%5E' => '^',
633+
'%60' => '`',
634+
'%7B' => '{',
635+
'%7C' => '|',
636+
'%7D' => '}',
637+
]);
638+
}
639+
615640
foreach (explode('&', $queryString) as $v) {
616641
$queryArray[rawurldecode(explode('=', $v, 2)[0])] = $v;
617642
}

HttplugClient.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Symfony\Component\HttpClient;
1313

14-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory;
15-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Request;
16-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Uri;
1714
use GuzzleHttp\Promise\Promise as GuzzlePromise;
1815
use GuzzleHttp\Promise\RejectedPromise;
1916
use GuzzleHttp\Promise\Utils;
@@ -84,12 +81,12 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
8481
$this->promisePool = class_exists(Utils::class) ? new \SplObjectStorage() : null;
8582

8683
if (null === $responseFactory || null === $streamFactory) {
87-
if (!class_exists(Psr17Factory::class) && !class_exists(WellKnownPsr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
84+
if (!class_exists(Psr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
8885
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
8986
}
9087

9188
try {
92-
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : (class_exists(WellKnownPsr17Factory::class, false) ? new WellKnownPsr17Factory() : null);
89+
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
9390
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
9491
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
9592
} catch (NotFoundException $e) {
@@ -170,8 +167,6 @@ public function createRequest($method, $uri, array $headers = [], $body = null,
170167
$request = $this->responseFactory->createRequest($method, $uri);
171168
} elseif (class_exists(Request::class)) {
172169
$request = new Request($method, $uri);
173-
} elseif (class_exists(WellKnownPsr7Request::class)) {
174-
$request = new WellKnownPsr7Request($method, $uri);
175170
} elseif (class_exists(Psr17FactoryDiscovery::class)) {
176171
$request = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $uri);
177172
} else {
@@ -249,10 +244,6 @@ public function createUri($uri = ''): UriInterface
249244
return new Uri($uri);
250245
}
251246

252-
if (class_exists(WellKnownPsr7Uri::class)) {
253-
return new WellKnownPsr7Uri($uri);
254-
}
255-
256247
if (class_exists(Psr17FactoryDiscovery::class)) {
257248
return Psr17FactoryDiscovery::findUrlFactory()->createUri($uri);
258249
}

Psr18Client.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Symfony\Component\HttpClient;
1313

14-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory;
15-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Request;
16-
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Uri;
1714
use Http\Discovery\Exception\NotFoundException;
1815
use Http\Discovery\Psr17FactoryDiscovery;
1916
use Nyholm\Psr7\Factory\Psr17Factory;
@@ -65,12 +62,12 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
6562
$streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null;
6663

6764
if (null === $responseFactory || null === $streamFactory) {
68-
if (!class_exists(Psr17Factory::class) && !class_exists(WellKnownPsr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
65+
if (!class_exists(Psr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
6966
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
7067
}
7168

7269
try {
73-
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : (class_exists(WellKnownPsr17Factory::class, false) ? new WellKnownPsr17Factory() : null);
70+
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
7471
$responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
7572
$streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
7673
} catch (NotFoundException $e) {
@@ -149,10 +146,6 @@ public function createRequest(string $method, $uri): RequestInterface
149146
return new Request($method, $uri);
150147
}
151148

152-
if (class_exists(WellKnownPsr7Request::class)) {
153-
return new WellKnownPsr7Request($method, $uri);
154-
}
155-
156149
if (class_exists(Psr17FactoryDiscovery::class)) {
157150
return Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $uri);
158151
}
@@ -191,10 +184,6 @@ public function createUri(string $uri = ''): UriInterface
191184
return new Uri($uri);
192185
}
193186

194-
if (class_exists(WellKnownPsr7Uri::class)) {
195-
return new WellKnownPsr7Uri($uri);
196-
}
197-
198187
if (class_exists(Psr17FactoryDiscovery::class)) {
199188
return Psr17FactoryDiscovery::findUrlFactory()->createUri($uri);
200189
}

Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function __toString(): string
308308
'curl \\
309309
--compressed \\
310310
--request GET \\
311-
--url %1$shttp://localhost:8057/?foo=fooval&bar=newbarval&foobar%%5Bbaz%%5D=bazval&foobar%%5Bqux%%5D=quxval&bazqux%%5B0%%5D=bazquxval1&bazqux%%5B1%%5D=bazquxval2%1$s \\
311+
--url %1$shttp://localhost:8057/?foo=fooval&bar=newbarval&foobar[baz]=bazval&foobar[qux]=quxval&bazqux[0]=bazquxval1&bazqux[1]=bazquxval2%1$s \\
312312
--header %1$sAccept: */*%1$s \\
313313
--header %1$sAccept-Encoding: gzip%1$s \\
314314
--header %1$sUser-Agent: Symfony HttpClient/Native%1$s',

Tests/HttpClientTraitTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ public function provideParseUrl(): iterable
176176
yield [['http:', null, null, null, null], 'http:'];
177177
yield [['http:', null, 'bar', null, null], 'http:bar'];
178178
yield [[null, null, 'bar', '?a=1&c=c', null], 'bar?a=a&b=b', ['b' => null, 'c' => 'c', 'a' => 1]];
179-
yield [[null, null, 'bar', '?a=b+c&b=b', null], 'bar?a=b+c', ['b' => 'b']];
180-
yield [[null, null, 'bar', '?a=b%2B%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
181-
yield [[null, null, 'bar', '?a%5Bb%5D=c', null], 'bar', ['a' => ['b' => 'c']]];
182-
yield [[null, null, 'bar', '?a%5Bb%5Bc%5D=d', null], 'bar?a[b[c]=d', []];
183-
yield [[null, null, 'bar', '?a%5Bb%5D%5Bc%5D=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
184-
yield [[null, null, 'bar', '?a=b&a%5Bb%20c%5D=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '']];
179+
yield [[null, null, 'bar', '?a=b+c&b=b-._~!$%26/%27()[]*+,;%3D:@%25\\^`{|}', null], 'bar?a=b+c', ['b' => 'b-._~!$&/\'()[]*+,;=:@%\\^`{|}']];
180+
yield [[null, null, 'bar', '?a=b+%20c', null], 'bar?a=b+c', ['a' => 'b+ c']];
181+
yield [[null, null, 'bar', '?a[b]=c', null], 'bar', ['a' => ['b' => 'c']]];
182+
yield [[null, null, 'bar', '?a[b[c]=d', null], 'bar?a[b[c]=d', []];
183+
yield [[null, null, 'bar', '?a[b][c]=dd', null], 'bar?a[b][c]=d&e[f]=g', ['a' => ['b' => ['c' => 'dd']], 'e[f]' => null]];
184+
yield [[null, null, 'bar', '?a=b&a[b%20c]=d&e%3Df=%E2%9C%93', null], 'bar?a=b', ['a' => ['b c' => 'd'], 'e=f' => '']];
185185
// IDNA 2008 compliance
186186
yield [['https:', '//xn--fuball-cta.test', null, null, null], 'https://fußball.test'];
187187
}

0 commit comments

Comments
 (0)