Skip to content

Commit 099481f

Browse files
Merge branch '3.4' into 4.4
* 3.4: [Http Foundation] Fix clear cookie samesite [Security] Check if firewall is stateless before checking for session/previous session [Form] Support customized intl php.ini settings [Security] Remember me: allow to set the samesite cookie flag [Debug] fix for PHP 7.3.16+/7.4.4+ [Validator] Backport translations Prevent warning in proc_open()
2 parents cd17611 + 438d9e5 commit 099481f

File tree

17 files changed

+124
-18
lines changed

17 files changed

+124
-18
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public function handleError($type, $message, $file, $line)
499499
if ($this->isRecursive) {
500500
$log = 0;
501501
} else {
502-
if (!\defined('HHVM_VERSION')) {
502+
if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404) && !\defined('HHVM_VERSION')) {
503503
$currentErrorHandler = set_error_handler('var_dump');
504504
restore_error_handler();
505505
}
@@ -511,7 +511,7 @@ public function handleError($type, $message, $file, $line)
511511
} finally {
512512
$this->isRecursive = false;
513513

514-
if (!\defined('HHVM_VERSION')) {
514+
if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404) && !\defined('HHVM_VERSION')) {
515515
set_error_handler($currentErrorHandler);
516516
}
517517
}

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ public function testHandleDeprecation()
329329
$handler = new ErrorHandler();
330330
$handler->setDefaultLogger($logger);
331331
@$handler->handleError(E_USER_DEPRECATED, 'Foo deprecation', __FILE__, __LINE__, []);
332-
333-
restore_error_handler();
334332
}
335333

336334
public function testHandleException()

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public function handleError(int $type, string $message, string $file, int $line)
519519
if ($this->isRecursive) {
520520
$log = 0;
521521
} else {
522-
if (!\defined('HHVM_VERSION')) {
522+
if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404)) {
523523
$currentErrorHandler = set_error_handler('var_dump');
524524
restore_error_handler();
525525
}
@@ -531,7 +531,7 @@ public function handleError(int $type, string $message, string $file, int $line)
531531
} finally {
532532
$this->isRecursive = false;
533533

534-
if (!\defined('HHVM_VERSION')) {
534+
if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404)) {
535535
set_error_handler($currentErrorHandler);
536536
}
537537
}

src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ public function testHandleDeprecation()
363363
$handler = new ErrorHandler();
364364
$handler->setDefaultLogger($logger);
365365
@$handler->handleError(E_USER_DEPRECATED, 'Foo deprecation', __FILE__, __LINE__, []);
366-
367-
restore_error_handler();
368366
}
369367

370368
/**
@@ -618,6 +616,10 @@ public function errorHandlerWhenLoggingProvider(): iterable
618616

619617
public function testAssertQuietEval()
620618
{
619+
if ('-1' === ini_get('zend.assertions')) {
620+
$this->markTestSkipped('zend.assertions is forcibly disabled');
621+
}
622+
621623
$ini = [
622624
ini_set('zend.assertions', 1),
623625
ini_set('assert.active', 1),

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ public function reverseTransform($value)
117117
// date-only patterns require parsing to be done in UTC, as midnight might not exist in the local timezone due
118118
// to DST changes
119119
$dateOnly = $this->isPatternDateOnly();
120+
$dateFormatter = $this->getIntlDateFormatter($dateOnly);
120121

121-
$timestamp = $this->getIntlDateFormatter($dateOnly)->parse($value);
122+
try {
123+
$timestamp = @$dateFormatter->parse($value);
124+
} catch (\IntlException $e) {
125+
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
126+
}
122127

123128
if (0 != intl_get_error_code()) {
124-
throw new TransformationFailedException(intl_get_error_message());
129+
throw new TransformationFailedException(intl_get_error_message(), intl_get_error_code());
125130
} elseif ($timestamp > 253402214400) {
126131
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
127132
throw new TransformationFailedException('Years beyond 9999 are not supported.');

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ protected function setUp(): void
2727
{
2828
parent::setUp();
2929

30+
// Normalize intl. configuration settings.
31+
if (\extension_loaded('intl')) {
32+
$this->iniSet('intl.use_exceptions', 0);
33+
$this->iniSet('intl.error_level', 0);
34+
}
35+
3036
// Since we test against "de_AT", we need the full implementation
3137
IntlTestHelper::requireFullIntl($this, '57.1');
3238

@@ -322,4 +328,44 @@ public function testReverseTransformFiveDigitYearsWithTimestamp()
322328
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss');
323329
$transformer->reverseTransform('20107-03-21 12:34:56');
324330
}
331+
332+
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
333+
{
334+
if (!\extension_loaded('intl')) {
335+
$this->markTestSkipped('intl extension is not loaded');
336+
}
337+
338+
$this->iniSet('intl.error_level', E_WARNING);
339+
340+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
341+
$transformer = new DateTimeToLocalizedStringTransformer();
342+
$transformer->reverseTransform('12345');
343+
}
344+
345+
public function testReverseTransformWrapsIntlErrorsWithExceptions()
346+
{
347+
if (!\extension_loaded('intl')) {
348+
$this->markTestSkipped('intl extension is not loaded');
349+
}
350+
351+
$this->iniSet('intl.use_exceptions', 1);
352+
353+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
354+
$transformer = new DateTimeToLocalizedStringTransformer();
355+
$transformer->reverseTransform('12345');
356+
}
357+
358+
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
359+
{
360+
if (!\extension_loaded('intl')) {
361+
$this->markTestSkipped('intl extension is not loaded');
362+
}
363+
364+
$this->iniSet('intl.use_exceptions', 1);
365+
$this->iniSet('intl.error_level', E_WARNING);
366+
367+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
368+
$transformer = new DateTimeToLocalizedStringTransformer();
369+
$transformer->reverseTransform('12345');
370+
}
325371
}

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,13 @@ public function getCookies($format = self::COOKIES_FLAT)
252252
* @param string $domain
253253
* @param bool $secure
254254
* @param bool $httpOnly
255+
* @param string $sameSite
255256
*/
256-
public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true)
257+
public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true/*, $sameSite = null*/)
257258
{
258-
$this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, null));
259+
$sameSite = \func_num_args() > 5 ? func_get_arg(5) : null;
260+
261+
$this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly, false, $sameSite));
259262
}
260263

261264
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ public function testClearCookieSecureNotHttpOnly()
128128
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
129129
}
130130

131+
public function testClearCookieSamesite()
132+
{
133+
$bag = new ResponseHeaderBag([]);
134+
135+
$bag->clearCookie('foo', '/', null, true, false, 'none');
136+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure; samesite=none', $bag);
137+
}
138+
131139
public function testReplace()
132140
{
133141
$bag = new ResponseHeaderBag([]);

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function start(callable $callback = null, array $env = [])
336336
throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.', $this->cwd));
337337
}
338338

339-
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $options);
339+
$this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $options);
340340

341341
if (!\is_resource($this->process)) {
342342
throw new RuntimeException('Unable to launch a new process.');

src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function setSessionAuthenticationStrategy(SessionAuthenticationStrategyIn
127127

128128
private function migrateSession(Request $request, TokenInterface $token, ?string $providerKey)
129129
{
130-
if (!$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession() || \in_array($providerKey, $this->statelessProviderKeys, true)) {
130+
if (\in_array($providerKey, $this->statelessProviderKeys, true) || !$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession()) {
131131
return;
132132
}
133133

0 commit comments

Comments
 (0)