Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2909ca

Browse files
committed
Merge branch '4.4'
* 4.4: [Console] Add check for Konsole/Yakuake to disable hyperlinks [HTTP Foundation] Deprecate passing argument to method Request::isMethodSafe() [HttpClient] work around PHP 7.3 bug related to json_encode() [VarDumper] fix dumping the cloner itself Rename the Symfony Mailer service config to avoid conflict with SwitMailer Set default crypto method - Fix #31105 [Form] add missing symfony/service-contracts dependency [HttpClient] Don't throw InvalidArgumentException on bad Location header
2 parents 455a1aa + 7207849 commit d2909ca

File tree

19 files changed

+82
-42
lines changed

19 files changed

+82
-42
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8-
<service id="mailer" class="Symfony\Component\Mailer\Mailer">
8+
<service id="mailer.mailer" class="Symfony\Component\Mailer\Mailer">
99
<argument type="service" id="mailer.transport" />
1010
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />
1111
</service>
12-
<service id="Symfony\Component\Mailer\MailerInterface" alias="mailer" />
12+
<service id="mailer" alias="mailer.mailer" />
13+
<service id="Symfony\Component\Mailer\MailerInterface" alias="mailer.mailer" />
1314

1415
<service id="mailer.transport" class="Symfony\Component\Mailer\Transport\TransportInterface">
1516
<factory class="Symfony\Component\Mailer\Transport" method="fromDsn" />

src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function apply($text)
187187
$unsetCodes = [];
188188

189189
if (null === $this->handlesHrefGracefully) {
190-
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
190+
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && !getenv('KONSOLE_VERSION');
191191
}
192192

193193
if (null !== $this->foreground) {

src/Symfony/Component/Form/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"symfony/options-resolver": "^4.4|^5.0",
2323
"symfony/polyfill-ctype": "~1.8",
2424
"symfony/polyfill-mbstring": "~1.0",
25-
"symfony/property-access": "^4.4|^5.0"
25+
"symfony/property-access": "^4.4|^5.0",
26+
"symfony/service-contracts": "~1.1"
2627
},
2728
"require-dev": {
2829
"doctrine/collections": "~1.0",

src/Symfony/Component/HttpClient/CurlHttpClient.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Log\LoggerAwareInterface;
1515
use Psr\Log\LoggerAwareTrait;
1616
use Psr\Log\LoggerInterface;
17+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1718
use Symfony\Component\HttpClient\Exception\TransportException;
1819
use Symfony\Component\HttpClient\Internal\CurlClientState;
1920
use Symfony\Component\HttpClient\Internal\PushedResponse;
@@ -392,14 +393,20 @@ private static function createRedirectResolver(array $options, string $host): \C
392393
}
393394

394395
return static function ($ch, string $location) use ($redirectHeaders) {
395-
if ($redirectHeaders && $host = parse_url($location, PHP_URL_HOST)) {
396+
try {
397+
$location = self::parseUrl($location);
398+
} catch (InvalidArgumentException $e) {
399+
return null;
400+
}
401+
402+
if ($redirectHeaders && $host = parse_url('http:'.$location['authority'], PHP_URL_HOST)) {
396403
$requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
397404
curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders);
398405
}
399406

400407
$url = self::parseUrl(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
401408

402-
return implode('', self::resolveUrl(self::parseUrl($location), $url));
409+
return implode('', self::resolveUrl($location, $url));
403410
};
404411
}
405412
}

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ private static function jsonEncode($value, int $flags = null, int $maxDepth = 51
301301
}
302302

303303
try {
304-
$value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth);
304+
if (\PHP_VERSION_ID >= 70300) {
305+
// Work around https://bugs.php.net/77997
306+
json_encode(null);
307+
$flags |= JSON_THROW_ON_ERROR;
308+
}
309+
310+
$value = json_encode($value, $flags, $maxDepth);
305311
} catch (\JsonException $e) {
306312
throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
307313
}

src/Symfony/Component/HttpClient/NativeHttpClient.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Psr\Log\LoggerAwareInterface;
1515
use Psr\Log\LoggerAwareTrait;
16+
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
1617
use Symfony\Component\HttpClient\Exception\TransportException;
1718
use Symfony\Component\HttpClient\Internal\NativeClientState;
1819
use Symfony\Component\HttpClient\Response\NativeResponse;
@@ -352,7 +353,15 @@ private static function createRedirectResolver(array $options, string $host, ?ar
352353
return null;
353354
}
354355

355-
$url = self::resolveUrl(self::parseUrl($location), $info['url']);
356+
try {
357+
$url = self::parseUrl($location);
358+
} catch (InvalidArgumentException $e) {
359+
$info['redirect_url'] = null;
360+
361+
return null;
362+
}
363+
364+
$url = self::resolveUrl($url, $info['url']);
356365
$info['redirect_url'] = implode('', $url);
357366

358367
if ($info['redirect_count'] >= $maxRedirects) {

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,19 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
310310
$info['redirect_url'] = null;
311311

312312
if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
313-
$info['redirect_url'] = $resolveRedirect($ch, $location);
314-
$url = parse_url($location ?? ':');
315-
316-
if (isset($url['host']) && null !== $ip = $multi->dnsCache->hostnames[$url['host'] = strtolower($url['host'])] ?? null) {
317-
// Populate DNS cache for redirects if needed
318-
$port = $url['port'] ?? ('http' === ($url['scheme'] ?? parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_SCHEME)) ? 80 : 443);
319-
curl_setopt($ch, CURLOPT_RESOLVE, ["{$url['host']}:$port:$ip"]);
320-
$multi->dnsCache->removals["-{$url['host']}:$port"] = "-{$url['host']}:$port";
313+
if (null === $info['redirect_url'] = $resolveRedirect($ch, $location)) {
314+
$options['max_redirects'] = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT);
315+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
316+
curl_setopt($ch, CURLOPT_MAXREDIRS, $options['max_redirects']);
317+
} else {
318+
$url = parse_url($location ?? ':');
319+
320+
if (isset($url['host']) && null !== $ip = $multi->dnsCache->hostnames[$url['host'] = strtolower($url['host'])] ?? null) {
321+
// Populate DNS cache for redirects if needed
322+
$port = $url['port'] ?? ('http' === ($url['scheme'] ?? parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_SCHEME)) ? 80 : 443);
323+
curl_setopt($ch, CURLOPT_RESOLVE, ["{$url['host']}:$port:$ip"]);
324+
$multi->dnsCache->removals["-{$url['host']}:$port"] = "-{$url['host']}:$port";
325+
}
321326
}
322327
}
323328

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function prepare(Request $request)
204204

205205
if (!$this->headers->has('Accept-Ranges')) {
206206
// Only accept ranges on safe HTTP methods
207-
$this->headers->set('Accept-Ranges', $request->isMethodSafe(false) ? 'bytes' : 'none');
207+
$this->headers->set('Accept-Ranges', $request->isMethodSafe() ? 'bytes' : 'none');
208208
}
209209

210210
if (self::$trustXSendfileTypeHeader && $request->headers->has('X-Sendfile-Type')) {

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.4.0
5+
-----
6+
7+
* passing arguments to `Request::isMethodSafe()` is deprecated.
8+
49
4.3.0
510
-----
611

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,12 @@ public function isMethod($method)
14371437
*
14381438
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
14391439
*
1440-
* @param bool $andCacheable Adds the additional condition that the method should be cacheable. True by default.
1441-
*
14421440
* @return bool
14431441
*/
1444-
public function isMethodSafe(/* $andCacheable = true */)
1442+
public function isMethodSafe()
14451443
{
1446-
if (!\func_num_args() || func_get_arg(0)) {
1447-
// setting $andCacheable to false should be deprecated in 4.1
1448-
throw new \BadMethodCallException('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is not supported.');
1444+
if (\func_num_args() > 0) {
1445+
@trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable() to check if the method is cacheable instead."', __METHOD__, __CLASS__), E_USER_DEPRECATED);
14491446
}
14501447

14511448
return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']);

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ public function testMethodSafe($method, $safe)
21152115
{
21162116
$request = new Request();
21172117
$request->setMethod($method);
2118-
$this->assertEquals($safe, $request->isMethodSafe(false));
2118+
$this->assertEquals($safe, $request->isMethodSafe());
21192119
}
21202120

21212121
public function methodSafeProvider()
@@ -2134,16 +2134,6 @@ public function methodSafeProvider()
21342134
];
21352135
}
21362136

2137-
/**
2138-
* @expectedException \BadMethodCallException
2139-
*/
2140-
public function testMethodSafeChecksCacheable()
2141-
{
2142-
$request = new Request();
2143-
$request->setMethod('OPTIONS');
2144-
$request->isMethodSafe();
2145-
}
2146-
21472137
/**
21482138
* @dataProvider methodCacheableProvider
21492139
*/

src/Symfony/Component/HttpKernel/EventListener/FragmentListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function onKernelRequest(GetResponseEvent $event)
7979
protected function validateRequest(Request $request)
8080
{
8181
// is the Request safe?
82-
if (!$request->isMethodSafe(false)) {
82+
if (!$request->isMethodSafe()) {
8383
throw new AccessDeniedHttpException();
8484
}
8585

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
207207

208208
$this->traces[$this->getTraceKey($request)] = [];
209209

210-
if (!$request->isMethodSafe(false)) {
210+
if (!$request->isMethodSafe()) {
211211
$response = $this->invalidate($request, $catch);
212212
} elseif ($request->headers->has('expect') || !$request->isMethodCacheable()) {
213213
$response = $this->pass($request, $catch);

src/Symfony/Component/Mailer/Transport/Smtp/Stream/SocketStream.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public function initialize(): void
140140
if ($this->streamContextOptions) {
141141
$options = array_merge($options, $this->streamContextOptions);
142142
}
143+
if ($this->isTLS()) {
144+
$options['ssl']['crypto_method'] = $options['ssl']['crypto_method'] ?? STREAM_CRYPTO_METHOD_TLS_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
145+
}
143146
$streamContext = stream_context_create($options);
144147
$this->stream = @stream_socket_client($this->url, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $streamContext);
145148
if (false === $this->stream) {

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function startAuthentication(Request $request, AuthenticationException $
208208
protected function setTargetPath(Request $request)
209209
{
210210
// session isn't required when using HTTP basic authentication mechanism for example
211-
if ($request->hasSession() && $request->isMethodSafe(false) && !$request->isXmlHttpRequest()) {
211+
if ($request->hasSession() && $request->isMethodSafe() && !$request->isXmlHttpRequest()) {
212212
$this->saveTargetPath($request->getSession(), $this->providerKey, $request->getUri());
213213
}
214214
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ abstract class AbstractCloner implements ClonerInterface
8484
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
8585
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
8686
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
87+
'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
8788
'Symfony\Component\Debug\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
8889

8990
'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
@@ -188,10 +189,7 @@ public function __construct(array $casters = null)
188189
public function addCasters(array $casters)
189190
{
190191
foreach ($casters as $type => $callback) {
191-
$closure = &$this->casters[$type][];
192-
$closure = $callback instanceof \Closure ? $callback : static function (...$args) use ($callback, &$closure) {
193-
return ($closure = \Closure::fromCallable($callback))(...$args);
194-
};
192+
$this->casters[$type][] = $callback;
195193
}
196194
}
197195

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ protected function style($style, $value, $attr = [])
435435
}
436436

437437
if (null === $this->handlesHrefGracefully) {
438-
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR');
438+
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && !getenv('KONSOLE_VERSION');
439439
}
440440

441441
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {

src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
header('Location: http://foo.example.', true, 301);
5656
break;
5757

58+
case '/301/invalid':
59+
header('Location: //?foo=bar', true, 301);
60+
break;
61+
5862
case '/302':
5963
if (!isset($vars['HTTP_AUTHORIZATION'])) {
6064
header('Location: http://localhost:8057/', true, 302);

src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@ public function testRedirects()
259259
$this->assertSame($expected, $filteredHeaders);
260260
}
261261

262+
public function testInvalidRedirect()
263+
{
264+
$client = $this->getHttpClient(__FUNCTION__);
265+
$response = $client->request('GET', 'http://localhost:8057/301/invalid');
266+
267+
$this->assertSame(301, $response->getStatusCode());
268+
$this->assertSame(['//?foo=bar'], $response->getHeaders(false)['location']);
269+
$this->assertSame(0, $response->getInfo('redirect_count'));
270+
$this->assertNull($response->getInfo('redirect_url'));
271+
272+
$this->expectException(RedirectionExceptionInterface::class);
273+
$response->getHeaders();
274+
}
275+
262276
public function testRelativeRedirects()
263277
{
264278
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)