Skip to content

Commit 330d337

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date [ExpressionLanguage] Improve test coverage [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent [Security] consistent singular/plural translation in Dutch reset the validation context after validating nested constraints do not duplicate directory separators fix handling empty data in ValueToDuplicatesTransformer [Validator] review latvian translations [Validator] Add Dutch translation for `WordCount` constraint allow more unicode characters in URL paths [String][EnglishInflector] Fix words ending in 'le', e.g., articles do not duplicate directory separators [Uid] Ensure UuidV1 is created in lowercase
2 parents 67dd6a3 + 10fd29d commit 330d337

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function reverseTransform(mixed $value): int|float|null
106106
$value = str_replace(',', $decSep, $value);
107107
}
108108

109-
if (str_contains($value, $decSep)) {
109+
//If the value is in exponential notation with a negative exponent, we end up with a float value too
110+
if (str_contains($value, $decSep) || false !== stripos($value, 'e-')) {
110111
$type = \NumberFormatter::TYPE_DOUBLE;
111112
} else {
112113
$type = \PHP_INT_SIZE === 8

Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function reverseTransform(mixed $array): mixed
5858
$emptyKeys = [];
5959

6060
foreach ($this->keys as $key) {
61-
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && [] !== $array[$key]) {
61+
if (isset($array[$key]) && false !== $array[$key] && [] !== $array[$key]) {
6262
if ($array[$key] !== $result) {
6363
throw new TransformationFailedException('All values in the array should be the same.');
6464
}

Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,33 @@ public function testReverseTransformSmallInt()
632632

633633
$this->assertSame(1.0, $transformer->reverseTransform('1'));
634634
}
635+
636+
/**
637+
* @dataProvider eNotationProvider
638+
*/
639+
public function testReverseTransformENotation($output, $input)
640+
{
641+
IntlTestHelper::requireFullIntl($this);
642+
643+
\Locale::setDefault('en');
644+
645+
$transformer = new NumberToLocalizedStringTransformer();
646+
647+
$this->assertSame($output, $transformer->reverseTransform($input));
648+
}
649+
650+
public static function eNotationProvider(): array
651+
{
652+
return [
653+
[0.001, '1E-3'],
654+
[0.001, '1.0E-3'],
655+
[0.001, '1e-3'],
656+
[0.001, '1.0e-03'],
657+
[1000.0, '1E3'],
658+
[1000.0, '1.0E3'],
659+
[1000.0, '1e3'],
660+
[1000.0, '1.0e3'],
661+
[1232.0, '1.232e3'],
662+
];
663+
}
635664
}

Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testReverseTransformCompletelyEmpty()
6565
'c' => '',
6666
];
6767

68-
$this->assertNull($this->transformer->reverseTransform($input));
68+
$this->assertSame('', $this->transformer->reverseTransform($input));
6969
}
7070

7171
public function testReverseTransformCompletelyNull()

Tests/Extension/Core/Type/RepeatedTypeTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Component\Form\Extension\Core\Type\TextType;
1415
use Symfony\Component\Form\Form;
1516
use Symfony\Component\Form\Tests\Fixtures\NotMappedType;
1617
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
@@ -188,6 +189,36 @@ public function testSetOptionsPerChildAndOverwrite()
188189
$this->assertTrue($form['second']->isRequired());
189190
}
190191

192+
/**
193+
* @dataProvider emptyDataProvider
194+
*/
195+
public function testSubmitNullForTextTypeWithEmptyDataOptionSetToEmptyString($emptyData, $submittedData, $expected)
196+
{
197+
$form = $this->factory->create(static::TESTED_TYPE, null, [
198+
'type' => TextType::class,
199+
'options' => [
200+
'empty_data' => $emptyData,
201+
]
202+
]);
203+
$form->submit($submittedData);
204+
205+
$this->assertSame($expected, $form->getData());
206+
}
207+
208+
public static function emptyDataProvider()
209+
{
210+
yield ['', null, ''];
211+
yield ['', ['first' => null, 'second' => null], ''];
212+
yield ['', ['first' => '', 'second' => null], ''];
213+
yield ['', ['first' => null, 'second' => ''], ''];
214+
yield ['', ['first' => '', 'second' => ''], ''];
215+
yield [null, null, null];
216+
yield [null, ['first' => null, 'second' => null], null];
217+
yield [null, ['first' => '', 'second' => null], null];
218+
yield [null, ['first' => null, 'second' => ''], null];
219+
yield [null, ['first' => '', 'second' => ''], null];
220+
}
221+
191222
public function testSubmitUnequal()
192223
{
193224
$input = ['first' => 'foo', 'second' => 'bar'];

0 commit comments

Comments
 (0)