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

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7207849

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [Console] Add check for Konsole/Yakuake to disable hyperlinks [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 5c8fb7b + d90dd8d commit 7207849

File tree

12 files changed

+69
-21
lines changed

12 files changed

+69
-21
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.3|^5.0",
2323
"symfony/polyfill-ctype": "~1.8",
2424
"symfony/polyfill-mbstring": "~1.0",
25-
"symfony/property-access": "^3.4|^4.0|^5.0"
25+
"symfony/property-access": "^3.4|^4.0|^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+
10BBC 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/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/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)
0