From dbe335d9bea631692eed67aee3e7527870bb71b3 Mon Sep 17 00:00:00 2001 From: bilogic <> Date: Wed, 9 Sep 2020 00:09:14 +0800 Subject: [PATCH 1/9] guard $argv + $token against null, preventing unnecessary exceptions --- src/Symfony/Component/Console/Input/ArgvInput.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index b0c167d690..7f54323872 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -49,9 +49,7 @@ class ArgvInput extends Input */ public function __construct(array $argv = null, InputDefinition $definition = null) { - if (null === $argv) { - $argv = $_SERVER['argv']; - } + $argv = $argv ?? $_SERVER['argv'] ?? []; // strip the application name array_shift($argv); From 2a57ba52679dae52ee6e8f912a399b3bddb67680 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 8 Sep 2020 23:46:32 +0200 Subject: [PATCH 2/9] [Console] Silence warnings on sapi_windows_cp_set() call --- src/Symfony/Component/Console/Helper/QuestionHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index 15d4549dad..ac6f2be491 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -160,7 +160,7 @@ class QuestionHelper extends Helper if (\function_exists('sapi_windows_cp_set')) { // Codepage used by cmd.exe on Windows to allow special characters (éàüñ). - sapi_windows_cp_set(1252); + @sapi_windows_cp_set(1252); } if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) { From bf62a4d622bdef0d4c54dcbcdb69d40108c23331 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 9 Sep 2020 00:19:14 +0200 Subject: [PATCH 3/9] [Debug] Skip a test that was meant for HHVM. --- src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 05f24a24ca..12083d3f52 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -558,6 +558,10 @@ class ErrorHandlerTest extends TestCase */ public function testHandleFatalErrorOnHHVM() { + if (!\defined('HHVM_VERSION')) { + $this->markTestSkipped('This test requires HHVM.'); + } + try { $handler = ErrorHandler::register(); From 336946a499721b58bb9f6445f3b45daaf4b8a24f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 9 Sep 2020 07:09:37 +0200 Subject: [PATCH 4/9] Fix tests on 5.6 --- src/Symfony/Component/Console/Input/ArgvInput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 7f54323872..fb2b3584f9 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -49,7 +49,7 @@ class ArgvInput extends Input */ public function __construct(array $argv = null, InputDefinition $definition = null) { - $argv = $argv ?? $_SERVER['argv'] ?? []; + $argv = null !== $argv ? $argv : (isset($_SERVER['argv']) ? $_SERVER['argv'] : []); // strip the application name array_shift($argv); From 656fc3b82ab10f2bfeced39297c5724eb88dc92c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 9 Sep 2020 07:14:52 +0200 Subject: [PATCH 5/9] Simplify code --- src/Symfony/Component/Console/Input/ArgvInput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 4dbb0468cd..6d2946926f 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -48,7 +48,7 @@ class ArgvInput extends Input */ public function __construct(array $argv = null, InputDefinition $definition = null) { - $argv = null !== $argv ? $argv : (isset($_SERVER['argv']) ? $_SERVER['argv'] : []); + $argv = $argv ?? $_SERVER['argv'] ?? []; // strip the application name array_shift($argv); From cf9e75614b97b4f05355913933488a4114274ba4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 9 Sep 2020 07:19:58 +0200 Subject: [PATCH 6/9] Remove some leftover for HHVM support --- src/Symfony/Component/Debug/ErrorHandler.php | 4 ++-- .../Tests/Session/Storage/NativeSessionStorageTest.php | 4 ---- .../Component/VarDumper/Tests/Caster/ReflectionCasterTest.php | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index b1db015e01..6d562c5f56 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -489,7 +489,7 @@ class ErrorHandler if ($this->isRecursive) { $log = 0; } else { - if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404) && !\defined('HHVM_VERSION')) { + if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404)) { $currentErrorHandler = set_error_handler('var_dump'); restore_error_handler(); } @@ -501,7 +501,7 @@ class ErrorHandler } finally { $this->isRecursive = false; - if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404) && !\defined('HHVM_VERSION')) { + if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404)) { set_error_handler($currentErrorHandler); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index 4cb0b2dab3..a48da9df97 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -194,10 +194,6 @@ class NativeSessionStorageTest extends TestCase public function testSessionOptions() { - if (\defined('HHVM_VERSION')) { - $this->markTestSkipped('HHVM is not handled in this test case.'); - } - $options = [ 'url_rewriter.tags' => 'a=href', 'cache_expire' => '200', diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 293afd94eb..a4183e21af 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -84,9 +84,6 @@ EOTXT public function testFromCallableClosureCaster() { - if (\defined('HHVM_VERSION_ID')) { - $this->markTestSkipped('Not for HHVM.'); - } $var = [ (new \ReflectionMethod($this, __FUNCTION__))->getClosure($this), (new \ReflectionMethod(__CLASS__, 'stub'))->getClosure(), From 27f6e28f5b3858497019097572351e2db948fce6 Mon Sep 17 00:00:00 2001 From: Stefan Kleff Date: Thu, 4 Jun 2020 13:47:59 +0200 Subject: [PATCH 7/9] DateTime validator support for trailing data --- .../Component/Validator/Constraints/DateTimeValidator.php | 6 ++++++ .../Validator/Tests/Constraints/DateTimeValidatorTest.php | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index bad043f20e..8d0350532d 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -57,6 +57,12 @@ class DateTimeValidator extends DateValidator return; } + if('+' === substr($constraint->format, -1)) { + $errors['warnings'] = array_filter($errors['warnings'], function($warning) { + return 'Trailing data' !== $warning; + }); + } + foreach ($errors['warnings'] as $warning) { if ('The parsed date was invalid' === $warning) { $this->context->buildViolation($constraint->message) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 55bfe45143..8ff515772d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -128,4 +128,12 @@ class DateTimeValidatorTest extends ConstraintValidatorTestCase ['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR], ]; } + + public function testDateTimeWithTrailingData() + { + $this->validator->validate('1995-05-10 00:00:00', new DateTime([ + 'format' => 'Y-m-d+', + ])); + $this->assertNoViolation(); + } } From 799624b6f1ec586e2cb49e688378219a154d28f2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 9 Sep 2020 07:35:36 +0200 Subject: [PATCH 8/9] Fix CS --- .../Component/Validator/Constraints/DateTimeValidator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 8d0350532d..9a1398681f 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -57,8 +57,8 @@ class DateTimeValidator extends DateValidator return; } - if('+' === substr($constraint->format, -1)) { - $errors['warnings'] = array_filter($errors['warnings'], function($warning) { + if ('+' === substr($constraint->format, -1)) { + $errors['warnings'] = array_filter($errors['warnings'], function ($warning) { return 'Trailing data' !== $warning; }); } From 82d9d41d573f10dae058f88318e6759b22dedd01 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Sep 2020 09:04:38 +0200 Subject: [PATCH 9/9] [Intl] promote warnings to value errors on PHP 8 --- .../Intl/NumberFormatter/NumberFormatter.php | 8 ++++++++ .../AbstractNumberFormatterTest.php | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 72a110bf2a..579681ee6a 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -357,6 +357,10 @@ class NumberFormatter // The original NumberFormatter does not support this format type if (self::TYPE_CURRENCY === $type) { + if (\PHP_VERSION_ID >= 80000) { + throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type)); + } + trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); return false; @@ -513,6 +517,10 @@ class NumberFormatter $type = (int) $type; if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) { + if (\PHP_VERSION_ID >= 80000) { + throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type)); + } + trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); return false; diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index dd6a300c55..9cc628911b 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -324,7 +324,9 @@ abstract class AbstractNumberFormatterTest extends TestCase */ public function testFormatTypeCurrency($formatter, $value) { - if (method_exists($this, 'expectWarning')) { + if (\PHP_VERSION_ID >= 80000) { + $this->expectException(\ValueError::class); + } elseif (method_exists($this, 'expectWarning')) { $this->expectWarning(); } else { $this->expectException(Warning::class); @@ -338,6 +340,10 @@ abstract class AbstractNumberFormatterTest extends TestCase */ public function testFormatTypeCurrencyReturn($formatter, $value) { + if (\PHP_VERSION_ID >= 80000) { + $this->expectException(\ValueError::class); + } + $this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY)); } @@ -709,7 +715,9 @@ abstract class AbstractNumberFormatterTest extends TestCase public function testParseTypeDefault() { - if (method_exists($this, 'expectWarning')) { + if (\PHP_VERSION_ID >= 80000) { + $this->expectException(\ValueError::class); + } elseif (method_exists($this, 'expectWarning')) { $this->expectWarning(); } else { $this->expectException(Warning::class); @@ -833,7 +841,9 @@ abstract class AbstractNumberFormatterTest extends TestCase public function testParseTypeCurrency() { - if (method_exists($this, 'expectWarning')) { + if (\PHP_VERSION_ID >= 80000) { + $this->expectException(\ValueError::class); + } elseif (method_exists($this, 'expectWarning')) { $this->expectWarning(); } else { $this->expectException(Warning::class);