8000 [Form] Check if IntlDateFormatter constructor returned a valid object… · symfony/symfony@ebf967d · GitHub
[go: up one dir, main page]

Skip to content

Commit ebf967d

Browse files
committed
[Form] Check if IntlDateFormatter constructor returned a valid object before using it
1 parent 37931f4 commit ebf967d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ public function reverseTransform($value)
152152
* Returns a preconfigured IntlDateFormatter instance
153153
*
154154
* @return \IntlDateFormatter
155+
*
156+
* @throws TransformationFailedException in case the date formatter can not be constructed.
155157
*/
156158
protected function getIntlDateFormatter()
157159
{
@@ -162,6 +164,12 @@ protected function getIntlDateFormatter()
162164
$pattern = $this->pattern;
163165

164166
$intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern);
167+
168+
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
169+
if (!$intlDateFormatter) {
170+
throw new TransformationFailedException(intl_get_error_message(), intl_get_error_code());
171+
}
172+
165173
$intlDateFormatter->setLenient(false);
166174

167175
return $intlDateFormatter;

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7777
$calendar,
7878
$pattern
7979
);
80+
81+
// new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
82+
if (!$formatter) {
83+
throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
84+
}
85+
8086
$formatter->setLenient(false);
8187

8288
if ('choice' === $options['widget']) {

0 commit comments

Comments
 (0)
0