8000 Merge branch '4.4' into 5.1 · symfony/symfony@d825513 · GitHub
[go: up one dir, main page]

Skip to content

Commit d825513

Browse files
Merge branch '4.4' into 5.1
* 4.4: [HttpClient] fix using proxies with NativeHttpClient [4.4] Ignore more deprecations for Mockery mocks [Routing] fix using !important and defaults/reqs in inline route definitions [ErrorHandler][DebugClassLoader] Do not check Mockery mocks classes [HttpClient] Fix using https with proxies [TwigBundle] Only remove kernel exception listener if twig is used Adjust expired range check Fix redis connection error message
2 parents 0906428 + 0d8721f commit d825513

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 1 deletion
< 8000 td data-grid-cell-id="diff-e01cc9bd870fb40fe363b22fbfe4d69819fc550dca7f8d941d6a51b78a8cd0ec-307-307-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">307
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function isHttpOnly()
306306
*/
307
public function isExpired()
308308
{
309-
return null !== $this->expires && 0 != $this->expires && $this->expires < time();
309+
return null !== $this->expires && 0 != $this->expires && $this->expires <= time();
310310
}
311311

312312
/**

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Persistence\Proxy as LegacyProxy;
1515
use Doctrine\Persistence\Proxy;
16+
use Mockery\MockInterface;
1617
use PHPUnit\Framework\MockObject\Matcher\StatelessInvocation;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use Prophecy\Prophecy\ProphecySubjectInterface;
@@ -306,6 +307,7 @@ public static function checkClasses(): bool
306307
&& !is_subclass_of($symbols[$i], Proxy::class)
307308
&& !is_subclass_of($symbols[$i], ProxyInterface::class)
308309
&& !is_subclass_of($symbols[$i], LegacyProxy::class)
310+
&& !is_subclass_of($symbols[$i], MockInterface::class)
309311
) {
310312
$loader->checkClass($symbols[$i]);
311313
}

src/Symfony/Component/HttpClient/NativeHttpClient.php

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function request(string $method, string $url, array $options = []): Respo
171171

172172
$this->logger && $this->logger->info(sprintf('Request: "%s %s"', $method, implode('', $url)));
173173

174-
[$host, $port, $url['authority']] = self::dnsResolve($url, $this->multi, $info, $onProgress);
174+
[$host, $port] = self::parseHostPort($url, $info);
175175

176176
if (!isset($options['normalized_headers']['host'])) {
177177
$options['headers'][] = 'Host: '.$host.$port;
@@ -198,7 +198,6 @@ public function request(string $method, string $url, array $options = []): Respo
198198
'follow_location' => false, // We follow redirects ourselves - the native logic is too limited
199199
],
200200
'ssl' => array_filter([
201-
'peer_name' => $host,
202201
'verify_peer' => $options['verify_peer'],
203202
'verify_peer_name' => $options['verify_host'],
204203
'cafile' => $options['cafile'],
@@ -222,7 +221,11 @@ public function request(string $method, string $url, array $options = []): Respo
222221
$proxy = self::getProxy($options['proxy'], $url, $options['no_proxy']);
223222
$resolveRedirect = self::createRedirectResolver($options, $host, $proxy, $info, $onProgress);
224223
$context = stream_context_create($context, ['notification' => $notification]);
225-
self::configureHeadersAndProxy($context, $host, $options['headers'], $proxy);
224+
225+
if (!self::configureHeadersAndProxy($context, $host, $options['headers'], $proxy, 'https:' === $url['scheme'])) {
226+
$ip = self::dnsResolve($host, $this->multi, $info, $onProgress);
227+
$url['authority'] = substr_replace($url['authority'], $ip, -\strlen($host) - \strlen($port), \strlen($host));
228+
}
226229

227230
return new NativeResponse($this->multi, $context, implode('', $url), $options, $info, $resolveRedirect, $onProgress, $this->logger);
228231
}
@@ -265,9 +268,9 @@ private static function getBodyAsString($body): string
265268
}
266269

267270
/**
268-
* Resolves the IP of the host using the local DNS cache if possible.
271+
* Extracts the host and the port from the URL.
269272
*/
270-
private static function dnsResolve(array $url, NativeClientState $multi, array &$info, ?\Closure $onProgress): array
273+
private static function parseHostPort(array $url, array &$info): array
271274
{
272275
if ($port = parse_url($url['authority'], \PHP_URL_PORT) ?: '') {
273276
$info['primary_port'] = $port;
@@ -276,8 +279,14 @@ private static function dnsResolve(array $url, NativeClientState $multi, array &
276279
$info['primary_port'] = 'http:' === $url['scheme'] ? 80 : 443;
277280
}
278281

279-
$host = parse_url($url['authority'], \PHP_URL_HOST);
282+
return [parse_url($url['authority'], \PHP_URL_HOST), $port];
283+
}
280284

285+
/**
286+
* Resolves the IP of the host using the local DNS cache if possible.
287+
*/
288+
private static function dnsResolve($host, NativeClientState $multi, array &$info, ?\Closure $onProgress): string
289+
{
281290
if (null === $ip = $multi->dnsCache[$host] ?? null) {
282291
$info['debug'] .= "* Hostname was NOT found in DNS cache\n";
283292
$now = microtime(true);
@@ -300,7 +309,7 @@ private static function dnsResolve(array $url, NativeClientState $multi, array &
300309
$onProgress();
301310
}
302311

303-
return [$host, $port, substr_replace($url['authority'], $ip, -\strlen($host) - \strlen($port), \strlen($host))];
312+
return $ip;
304313
}
305314

306315
/**
@@ -363,24 +372,33 @@ private static function createRedirectResolver(array $options, string $host, ?ar
363372
}
364373
}
365374

366-
[$host, $port, $url['authority']] = self::dnsResolve($url, $multi, $info, $onProgress);
367-
stream_context_set_option($context, 'ssl', 'peer_name', $host);
375+
[$host, $port] = self::parseHostPort($url, $info);
368376

369377
if (false !== (parse_url($location, \PHP_URL_HOST) ?? false)) {
370378
// Authorization and Cookie headers MUST NOT follow except for the initial host name
371379
$requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
372380
$requestHeaders[] = 'Host: '.$host.$port;
373-
self::configureHeadersAndProxy($context, $host, $requestHeaders, $proxy);
381+
$dnsResolve = !self::configureHeadersAndProxy($context, $host, $requestHeaders, $proxy, 'https:' === $url['scheme']);
382+
} else {
383+
$dnsResolve = isset(stream_context_get_options($context)['ssl']['peer_name']);
384+
}
385+
386+
if ($dnsResolve) {
387+
$ip = self::dnsResolve($host, $multi, $info, $onProgress);
388+
$url['authority'] = substr_replace($url['authority'], $ip, -\strlen($host) - \strlen($port), \strlen($host));
374389
}
375390

376391
return implode('', $url);
377392
};
378393
}
379394

380-
private static function configureHeadersAndProxy($context, string $host, array $requestHeaders, ?array $proxy): bool
395+
private static function configureHeadersAndProxy($context, string $host, array $requestHeaders, ?array $proxy, bool $isSsl): bool
381396
{
382397
if (null === $proxy) {
383-
return stream_context_set_option($context, 'http', 'header', $requestHeaders);
398+
stream_context_set_option($context, 'http', 'header', $requestHeaders);
399+
stream_context_set_option($context, 'ssl', 'peer_name', $host);
400+
401+
return false;
384402
}
385403

386404
// Matching "no_proxy" should follow the behavior of curl
@@ -389,17 +407,24 @@ private static function configureHeadersAndProxy($context, string $host, array $
389407
$dotRule = '.'.ltrim($rule, '.');
390408

391409
if ('*' === $rule || $host === $rule || substr($host, -\strlen($dotRule)) === $dotRule) {
392-
return stream_context_set_option($context, 'http', 'header', $requestHeaders);
410+
stream_context_set_option($context, 'http', 'proxy', null);
411+
stream_context_set_option($context, 'http', 'request_fulluri', false);
412+
stream_context_set_option($context, 'http', 'header', $requestHeaders);
413+
stream_context_set_option($context, 'ssl', 'peer_name', $host);
414+
415+
return false;
393416
}
394417
}
395418

396-
stream_context_set_option($context, 'http', 'proxy', $proxy['url']);
397-
stream_context_set_option($context, 'http', 'request_fulluri', true);
398-
399419
if (null !== $proxy['auth']) {
400420
$requestHeaders[] = 'Proxy-Authorization: '.$proxy['auth'];
401421
}
402422

403-
return stream_context_set_option($context, 'http', 'header', $requestHeaders);
423+
stream_context_set_option($context, 'http', 'proxy', $proxy['url']);
424+
stream_context_set_option($context, 'http', 'request_fulluri', !$isSsl);
425+
stream_context_set_option($context, 'http', 'header', $requestHeaders);
426+
stream_context_set_option($context, 'ssl', 'peer_name', null);
427+
428+
return true;
404429
}
405430
}

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ public function __construct(array $configuration, array $connectionCredentials =
6969
}
7070

7171
if (null !== $auth && !$this->connection->auth($auth)) {
72-
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
72+
throw new InvalidArgumentException('Redis connection failed: '.$this->connection->getLastError());
7373
}
7474

7575
if (($dbIndex = $configuration['dbindex'] ?? self::DEFAULT_OPTIONS['dbindex']) && !$this->connection->select($dbIndex)) {
76-
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
76+
throw new InvalidArgumentException('Redis connection failed: '.$this->connection->getLastError());
7777
}
7878

7979
foreach (['stream', 'group', 'consumer'] as $key) {

src/Symfony/Component/Routing/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function getPath()
131131
public function setPath(string $pattern)
132132
{
133133
if (false !== strpbrk($pattern, '?<')) {
134-
$pattern = preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
134+
$pattern = preg_replace_callback('#\{(!?\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
135135
if (isset($m[3][0])) {
136136
$this->setDefault($m[1], '?' !== $m[3] ? substr($m[3], 1) : null);
137137
}

src/Symfony/Component/Routing/Tests/RouteTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public function testInlineDefaultAndRequirement()
207207
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null), new Route('/foo/{bar?}'));
208208
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?baz}'));
209209
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz<buz>'), new Route('/foo/{bar?baz<buz>}'));
210+
$this->assertEquals((new Route('/foo/{!bar}'))->setDefault('!bar', 'baz<buz>'), new Route('/foo/{!bar?baz<buz>}'));
210211
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?}', ['bar' => 'baz']));
211212

212213
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>}'));

0 commit comments

Comments
 (0)
0