From abb8a676ba782ea41afae738c8db2e7a6c28345b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 8 Aug 2019 19:35:41 +0200 Subject: [PATCH 1/5] Fix negative DateInterval --- .../Normalizer/DateIntervalNormalizer.php | 28 ++++++++++++++++-- .../Normalizer/DateIntervalNormalizerTest.php | 29 ++++++++++++++++--- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 56527a8eb4..bd43091bf1 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -29,7 +29,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa /** * @param string $format */ - public function __construct($format = 'P%yY%mM%dDT%hH%iM%sS') + public function __construct($format = '%rP%yY%mM%dDT%hH%iM%sS') { $this->format = $format; } @@ -76,12 +76,34 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa $dateIntervalFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : $this->format; - $valuePattern = '/^'.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?P<$1>\d+)$2', $dateIntervalFormat).'$/'; + $signPattern = ''; + switch (substr($dateIntervalFormat, 0, 2)) { + case '%R': + $signPattern = '[-+]'; + $dateIntervalFormat = substr($dateIntervalFormat, 2); + break; + case '%r': + $signPattern = '-?'; + $dateIntervalFormat = substr($dateIntervalFormat, 2); + break; + } + $valuePattern = '/^'.$signPattern.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?P<$1>\d+)$2', $dateIntervalFormat).'$/'; if (!preg_match($valuePattern, $data)) { throw new UnexpectedValueException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat)); } try { + if ('-' === $data[0]) { + $interval = new \DateInterval(substr($data, 1)); + $interval->invert = 1; + + return $interval; + } + + if ('+' === $data[0]) { + return new \DateInterval(substr($data, 1)); + } + return new \DateInterval($data); } catch (\Exception $e) { throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e); @@ -98,6 +120,6 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa private function isISO8601($string) { - return preg_match('/^P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string); + return preg_match('/^[\-+]?P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string); } } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php index efe34c6e95..f0bcdef161 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php @@ -29,6 +29,11 @@ class DateIntervalNormalizerTest extends TestCase ['P%yY%mM%dDT%hH%iM', 'P10Y2M3DT16H5M', 'P10Y2M3DT16H5M'], ['P%yY%mM%dDT%hH', 'P10Y2M3DT16H', 'P10Y2M3DT16H'], ['P%yY%mM%dD', 'P10Y2M3D', 'P10Y2M3DT0H'], + ['%RP%yY%mM%dD', '-P10Y2M3D', '-P10Y2M3DT0H'], + ['%RP%yY%mM%dD', '+P10Y2M3D', '+P10Y2M3DT0H'], + ['%RP%yY%mM%dD', '+P10Y2M3D', 'P10Y2M3DT0H'], + ['%rP%yY%mM%dD', '-P10Y2M3D', '-P10Y2M3DT0H'], + ['%rP%yY%mM%dD', 'P10Y2M3D', 'P10Y2M3DT0H'], ]; return $data; @@ -50,7 +55,7 @@ class DateIntervalNormalizerTest extends TestCase */ public function testNormalizeUsingFormatPassedInContext($format, $output, $input) { - $this->assertEquals($output, $this->normalizer->normalize(new \DateInterval($input), null, [DateIntervalNormalizer::FORMAT_KEY => $format])); + $this->assertEquals($output, $this->normalizer->normalize($this->getInterval($input), null, [DateIntervalNormalizer::FORMAT_KEY => $format])); } /** @@ -58,7 +63,7 @@ class DateIntervalNormalizerTest extends TestCase */ public function testNormalizeUsingFormatPassedInConstructor($format, $output, $input) { - $this->assertEquals($output, (new DateIntervalNormalizer($format))->normalize(new \DateInterval($input))); + $this->assertEquals($output, (new DateIntervalNormalizer($format))->normalize($this->getInterval($input))); } public function testNormalizeInvalidObjectThrowsException() @@ -84,7 +89,7 @@ class DateIntervalNormalizerTest extends TestCase */ public function testDenormalizeUsingFormatPassedInContext($format, $input, $output) { - $this->assertDateIntervalEquals(new \DateInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, [DateIntervalNormalizer::FORMAT_KEY => $format])); + $this->assertDateIntervalEquals($this->getInterval($input), $this->normalizer->denormalize($input, \DateInterval::class, null, [DateIntervalNormalizer::FORMAT_KEY => $format])); } /** @@ -92,7 +97,7 @@ class DateIntervalNormalizerTest extends TestCase */ public function testDenormalizeUsingFormatPassedInConstructor($format, $input, $output) { - $this->assertDateIntervalEquals(new \DateInterval($output), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class)); + $this->assertDateIntervalEquals($this->getInterval($input), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class)); } public function testDenormalizeExpectsString() @@ -124,4 +129,20 @@ class DateIntervalNormalizerTest extends TestCase { $this->assertEquals($expected->format('%RP%yY%mM%dDT%hH%iM%sS'), $actual->format('%RP%yY%mM%dDT%hH%iM%sS')); } + + private function getInterval($data) + { + if ('-' === $data[0]) { + $interval = new \DateInterval(substr($data, 1)); + $interval->invert = 1; + + return $interval; + } + + if ('+' === $data[0]) { + return new \DateInterval(substr($data, 1)); + } + + return new \DateInterval($data); + } } From 32a085a75fa7f66fd3c032761f6942e6834fd44a Mon Sep 17 00:00:00 2001 From: Jan Vernarsky Date: Fri, 9 Aug 2019 10:35:07 +0200 Subject: [PATCH 2/5] Added the missing translations for the Slovak 'sk' locale. --- .../Resources/translations/validators.sk.xlf | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf index 8ddb66d9c0..a161ddbfe8 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.sk.xlf @@ -314,6 +314,58 @@ This is not a valid Business Identifier Code (BIC). Táto hodnota nie je platný identifikačný kód podniku (BIC). + + Error + Chyba + + + This is not a valid UUID. + Táto hodnota nie je platný UUID. + + + This value should be a multiple of {{ compared_value }}. + Táto hodnota by mala byť násobkom {{ compared_value }}. + + + This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}. + Tento identifikačný kód podniku (BIC) nie je spojený s IBAN {{ iban }}. + + + This value should be valid JSON. + Táto hodnota by mala byť platný JSON. + + + This collection should contain only unique elements. + Táto kolekcia by mala obsahovať len unikátne prkvy. + + + This value should be positive. + Táto hodnota by mala byť kladná. + + + This value should be either positive or zero. + Táto hodnota by mala byť kladná alebo nulová. + + + This value should be negative. + Táto hodnota by mala byť záporná. + + + This value should be either negative or zero. + Táto hodnota by mala byť záporná alebo nulová. + + + This value is not a valid timezone. + Táto hodnota nie je platné časové pásmo. + + + This password has been leaked in a data breach, it must not be used. Please use another password. + Toto heslo uniklo pri narušení ochrany dát, nie je možné ho použiť. Prosím, použite iné heslo. + + + This value should be between {{ min }} and {{ max }}. + Táto hodnota by mala byť medzi {{ min }} a {{ max }}. + From 6e0c916eaf2e0fed1059c95c0de0d74bcfabd6e8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 9 Aug 2019 11:33:27 +0200 Subject: [PATCH 3/5] fix Danish translations --- .../Resources/translations/validators.da.xlf | 116 ------------------ .../Resources/translations/validators.da.xlf | 116 ++++++++++++++++++ 2 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/Symfony/Component/Form/Resources/translations/validators.da.xlf b/src/Symfony/Component/Form/Resources/translations/validators.da.xlf index 346e7cf574..f52f4e0a30 100644 --- a/src/Symfony/Component/Form/Resources/translations/validators.da.xlf +++ b/src/Symfony/Component/Form/Resources/translations/validators.da.xlf @@ -14,122 +14,6 @@ The CSRF token is invalid. Please try to resubmit the form. CSRF-token er ugyldig. - - This value is not a valid currency. - Denne værdi er ikke en gyldig valuta. - - - This value should be equal to {{ compared_value }}. - Denne værdi skal være lig med {{ compared_value }}. - - - This value should be greater than {{ compared_value }}. - Denne værdi skal være større end {{ compared_value }}. - - - This value should be greater than or equal to {{ compared_value }}. - Denne værdi skal være større end eller lig med {{ compared_value }}. - - - This value should be identical to {{ compared_value_type }} {{ compared_value }}. - Denne værdi skal være identisk med {{ compared_value_type }} {{ compared_value }}. - - - This value should be less than {{ compared_value }}. - Denne værdi skal være mindre end {{ compared_value }}. - - - This value should be less than or equal to {{ compared_value }}. - Denne værdi skal være mindre end eller lig med {{ compared_value }}. - - - This value should not be equal to {{ compared_value }}. - Denne værdi bør ikke være lig med {{ compared_value }}. - - - This value should not be identical to {{ compared_value_type }} {{ compared_value }}. - Denne værdi bør ikke være identisk med {{ compared_value_type }} {{ compared_value }}. - - - The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}. - Billedforholdet er for stort ({{ratio}}). Tilladt maksimumsforhold er {{ max_ratio }}. - - - The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}. - Billedforholdet er for lille ({{ ratio }}). Minimumsforventet forventet er {{ min_ratio }}. - - - The image is square ({{ width }}x{{ height }}px). Square images are not allowed. - Billedet er firkantet ({{ width }} x {{ height }} px). Firkantede billeder er ikke tilladt. - - - The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed. - Billedet er landskabsorienteret ({{width}} x {{height}} px). Landskabsorienterede billeder er ikke tilladt - - - The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed. - Billedet er portrætorienteret ({{ width }}x{{ height }}px). Portrætorienterede billeder er ikke tilladt. - - - An empty file is not allowed. - En tom fil er ikke tilladt. - - - The host could not be resolved. - Værten kunne ikke løses. - - - This value does not match the expected {{ charset }} charset. - Denne værdi stemmer ikke overens med den forventede {{ charset }} charset. - - - This is not a valid Business Identifier Code (BIC). - Dette er ikke en gyldig Business Identifier Code (BIC).a - - - This is not a valid UUID. - Dette er ikke en gyldig UUID. - - - This value should be a multiple of {{ compared_value }}. - Denne værdi skal være et flertal af {{ compared_value }}. - - - This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}. - Denne Business Identifier Code (BIC) er ikke forbundet med IBAN {{ iban }}. - - - This value should be valid JSON. - Denne værdi skal være gyldig JSON. - - - This collection should contain only unique elements. - Denne samling bør kun indeholde unikke elementer. - - - This value should be positive. - Denne værdi skal være positiv. - - - This value should be either positive or zero. - Denne værdi skal være enten positiv eller nul. - - - This value should be negative. - Denne værdi skal være negativ. - - - This value should be either negative or zero. - Denne værdi skal være enten negativ eller nul. - - - This value is not a valid timezone. - Denne værdi er ikke en gyldig tidszone. - - - This password has been leaked in a data breach, it must not be used. Please use another password. - Denne adgangskode er blevet lækket i et databrud, det må ikke bruges. Brug venligst en anden adgangskode. - diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf index e27bb2930f..2bc33a7b43 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.da.xlf @@ -242,10 +242,126 @@ This value is not a valid ISSN. Værdien er ikke en gyldig ISSN. + + This value is not a valid currency. + Denne værdi er ikke en gyldig valuta. + + + This value should be equal to {{ compared_value }}. + Denne værdi skal være lig med {{ compared_value }}. + + + This value should be greater than {{ compared_value }}. + Denne værdi skal være større end {{ compared_value }}. + + + This value should be greater than or equal to {{ compared_value }}. + Denne værdi skal være større end eller lig med {{ compared_value }}. + + + This value should be identical to {{ compared_value_type }} {{ compared_value }}. + Denne værdi skal være identisk med {{ compared_value_type }} {{ compared_value }}. + + + This value should be less than {{ compared_value }}. + Denne værdi skal være mindre end {{ compared_value }}. + + + This value should be less than or equal to {{ compared_value }}. + Denne værdi skal være mindre end eller lig med {{ compared_value }}. + + + This value should not be equal to {{ compared_value }}. + Denne værdi bør ikke være lig med {{ compared_value }}. + + + This value should not be identical to {{ compared_value_type }} {{ compared_value }}. + Denne værdi bør ikke være identisk med {{ compared_value_type }} {{ compared_value }}. + + + The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}. + Billedforholdet er for stort ({{ratio}}). Tilladt maksimumsforhold er {{ max_ratio }}. + + + The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}. + Billedforholdet er for lille ({{ ratio }}). Minimumsforventet forventet er {{ min_ratio }}. + + + The image is square ({{ width }}x{{ height }}px). Square images are not allowed. + Billedet er firkantet ({{ width }} x {{ height }} px). Firkantede billeder er ikke tilladt. + + + The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed. + Billedet er landskabsorienteret ({{width}} x {{height}} px). Landskabsorienterede billeder er ikke tilladt + + + The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed. + Billedet er portrætorienteret ({{ width }}x{{ height }}px). Portrætorienterede billeder er ikke tilladt. + + + An empty file is not allowed. + En tom fil er ikke tilladt. + + + The host could not be resolved. + Værten kunne ikke løses. + + + This value does not match the expected {{ charset }} charset. + Denne værdi stemmer ikke overens med den forventede {{ charset }} charset. + + + This is not a valid Business Identifier Code (BIC). + Dette er ikke en gyldig Business Identifier Code (BIC).a + Error Fejl + + This is not a valid UUID. + Dette er ikke en gyldig UUID. + + + This value should be a multiple of {{ compared_value }}. + Denne værdi skal være et flertal af {{ compared_value }}. + + + This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}. + Denne Business Identifier Code (BIC) er ikke forbundet med IBAN {{ iban }}. + + + This value should be valid JSON. + Denne værdi skal være gyldig JSON. + + + This collection should contain only unique elements. + Denne samling bør kun indeholde unikke elementer. + + + This value should be positive. + Denne værdi skal være positiv. + + + This value should be either positive or zero. + Denne værdi skal være enten positiv eller nul. + + + This value should be negative. + Denne værdi skal være negativ. + + + This value should be either negative or zero. + Denne værdi skal være enten negativ eller nul. + + + This value is not a valid timezone. + Denne værdi er ikke en gyldig tidszone. + + + This password has been leaked in a data breach, it must not be used. Please use another password. + Denne adgangskode er blevet lækket i et databrud, det må ikke bruges. Brug venligst en anden adgangskode. + This value should be between {{ min }} and {{ max }}. Værdien skal være mellem {{ min }} og {{ max }}. From 310e5c7549f85916304e8dda2479613eeb0892fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 9 Aug 2019 11:49:26 +0200 Subject: [PATCH 4/5] Fix unitialized variable in DeprecationErrorHandler --- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 8b355c31ff..22dbb829f9 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -48,7 +48,6 @@ class DeprecationErrorHandler } $UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\'; - self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke'); $getMode = function () use ($mode) { static $memoizedMode = false; @@ -304,6 +303,9 @@ class DeprecationErrorHandler */ public static function getPhpUnitErrorHandler() { + if (!isset(self::$isAtLeastPhpUnit83)) { + self::$isAtLeastPhpUnit83 = class_exists(ErrorHandler::class) && method_exists(ErrorHandler::class, '__invoke'); + } if (!self::$isAtLeastPhpUnit83) { return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError'; } From d851a794fc9b2e97add515b9d75d2594150bee87 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 9 Aug 2019 13:36:44 +0200 Subject: [PATCH 5/5] Fix typo --- phpunit | 2 +- src/Symfony/Bridge/PhpUnit/bin/simple-phpunit | 2 +- .../Tests/Normalizer/DateIntervalNormalizerTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpunit b/phpunit index 437f7b9b44..7b0b47cf7b 100755 --- a/phpunit +++ b/phpunit @@ -1,7 +1,7 @@ #!/usr/bin/env php assertDateIntervalEquals($this->getInterval($input), $this->normalizer->denormalize($input, \DateInterval::class, null, [DateIntervalNormalizer::FORMAT_KEY => $format])); + $this->assertDateIntervalEquals($this->getInterval($output), $this->normalizer->denormalize($input, \DateInterval::class, null, [DateIntervalNormalizer::FORMAT_KEY => $format])); } /** @@ -97,7 +97,7 @@ class DateIntervalNormalizerTest extends TestCase */ public function testDenormalizeUsingFormatPassedInConstructor($format, $input, $output) { - $this->assertDateIntervalEquals($this->getInterval($input), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class)); + $this->assertDateIntervalEquals($this->getInterval($output), (new DateIntervalNormalizer($format))->denormalize($input, \DateInterval::class)); } public function testDenormalizeExpectsString()