Skip to content

Commit 31f9abe

Browse files
committed
Catch JSONException for invalid formRuntimeData #523
1 parent 1fc7e45 commit 31f9abe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Form/Type/DynamicFormType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FormBuilderBundle\Form\Data\FormData;
1818
use Symfony\Component\Form\AbstractType;
1919
use Symfony\Component\Form\CallbackTransformer;
20+
use Symfony\Component\Form\Exception\TransformationFailedException;
2021
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
2122
use Symfony\Component\Form\FormBuilderInterface;
2223
use Symfony\Component\Form\FormError;
@@ -89,7 +90,11 @@ function ($runtimeData) {
8990
return is_array($runtimeData) ? json_encode($runtimeData, JSON_THROW_ON_ERROR) : null;
9091
},
9192
function ($runtimeData) {
92-
return empty($runtimeData) ? null : json_decode($runtimeData, true, 512, JSON_THROW_ON_ERROR);
93+
try {
94+
return empty($runtimeData) ? null : json_decode($runtimeData, true, 512, JSON_THROW_ON_ERROR);
95+
} catch (\jsonException $e) {
96+
throw new TransformationFailedException('', 0, $e);
97+
}
9398
}
9499
));
95100

0 commit comments

Comments
 (0)