Skip to content

Commit 3a287b3

Browse files
Merge branch '3.4' into 4.4
* 3.4: [Http Foundation] Fix clear cookie samesite [Security] Check if firewall is stateless before checking for session/previous session [Form] Support customized intl php.ini settings [Security] Remember me: allow to set the samesite cookie flag [Debug] fix for PHP 7.3.16+/7.4.4+ [Validator] Backport translations Prevent warning in proc_open()
2 parents bde3281 + 03ed019 commit 3a287b3

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ public function reverseTransform($value)
117117
// date-only patterns require parsing to be done in UTC, as midnight might not exist in the local timezone due
118118
// to DST changes
119119
$dateOnly = $this->isPatternDateOnly();
120+
$dateFormatter = $this->getIntlDateFormatter($dateOnly);
120121

121-
$timestamp = $this->getIntlDateFormatter($dateOnly)->parse($value);
122+
try {
123+
$timestamp = @$dateFormatter->parse($value);
124+
} catch (\IntlException $e) {
125+
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
126+
}
122127

123128
if (0 != intl_get_error_code()) {
124-
throw new TransformationFailedException(intl_get_error_message());
129+
throw new TransformationFailedException(intl_get_error_message(), intl_get_error_code());
125130
} elseif ($timestamp > 253402214400) {
126131
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
127132
throw new TransformationFailedException('Years beyond 9999 are not supported.');

Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ protected function setUp(): void
2727
{
2828
parent::setUp();
2929

30+
// Normalize intl. configuration settings.
31+
if (\extension_loaded('intl')) {
32+
$this->iniSet('intl.use_exceptions', 0);
33+
$this->iniSet('intl.error_level', 0);
34+
}
35+
3036
// Since we test against "de_AT", we need the full implementation
3137
IntlTestHelper::requireFullIntl($this, '57.1');
3238

@@ -322,4 +328,44 @@ public function testReverseTransformFiveDigitYearsWithTimestamp()
322328
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss');
323329
$transformer->reverseTransform('20107-03-21 12:34:56');
324330
}
331+
332+
public function testReverseTransformWrapsIntlErrorsWithErrorLevel()
333+
{
334+
if (!\extension_loaded('intl')) {
335+
$this->markTestSkipped('intl extension is not loaded');
336+
}
337+
338+
$this->iniSet('intl.error_level', E_WARNING);
339+
340+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
341+
$transformer = new DateTimeToLocalizedStringTransformer();
342+
$transformer->reverseTransform('12345');
343+
}
344+
345+
public function testReverseTransformWrapsIntlErrorsWithExceptions()
346+
{
347+
if (!\extension_loaded('intl')) {
348+
$this->markTestSkipped('intl extension is not loaded');
349+
}
350+
351+
$this->iniSet('intl.use_exceptions', 1);
352+
353+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
354+
$transformer = new DateTimeToLocalizedStringTransformer();
355+
$transformer->reverseTransform('12345');
356+
}
357+
358+
public function testReverseTransformWrapsIntlErrorsWithExceptionsAndErrorLevel()
359+
{
360+
if (!\extension_loaded('intl')) {
361+
$this->markTestSkipped('intl extension is not loaded');
362+
}
363+
364+
$this->iniSet('intl.use_exceptions', 1);
365+
$this->iniSet('intl.error_level', E_WARNING);
366+
367+
$this->expectException('Symfony\Component\Form\Exception\TransformationFailedException');
368+
$transformer = new DateTimeToLocalizedStringTransformer();
369+
$transformer->reverseTransform('12345');
370+
}
325371
}

0 commit comments

Comments
 (0)