Skip to content

Navigation Menu

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 b5aa55d

Browse filesBrowse files
committed
fix handling null as empty data
1 parent c6eb79a commit b5aa55d
Copy full SHA for b5aa55d

File tree

2 files changed

+17
-2
lines changed
Filter options

2 files changed

+17
-2
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ public function transform($value)
143143
*/
144144
public function reverseTransform($value)
145145
{
146-
if (!\is_string($value)) {
146+
if (null !== $value && !\is_string($value)) {
147147
throw new TransformationFailedException('Expected a string.');
148148
}
149149

150-
if ('' === $value) {
150+
if (null === $value || '' === $value) {
151151
return null;
152152
}
153153

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,19 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = '10', $expectedD
8585
$this->assertSame($expectedData, $form->getNormData());
8686
$this->assertSame($expectedData, $form->getData());
8787
}
88+
89+
public function testSubmitNullWithEmptyDataSetToNull()
90+
{
91+
$form = $this->factory->create(static::TESTED_TYPE, null, [
92+
'empty_data' => null,
93+
]);
94+
$form->submit(null);
95+
96+
$this->assertTrue($form->isSubmitted());
97+
$this->assertTrue($form->isSynchronized());
98+
$this->assertTrue($form->isValid());
99+
$this->assertSame('', $form->getViewData());
100+
$this->assertNull($form->getNormData());
101+
$this->assertNull($form->getData());
102+
}
88103
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.