[Form] Disallow transform dates beyond the year 9999
This commit is contained in:
parent
d78a98d793
commit
70cc969537
@ -123,6 +123,9 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
|
|
||||||
if (0 != intl_get_error_code()) {
|
if (0 != intl_get_error_code()) {
|
||||||
throw new TransformationFailedException(intl_get_error_message());
|
throw new TransformationFailedException(intl_get_error_message());
|
||||||
|
} elseif ($timestamp > 253402214400) {
|
||||||
|
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
|
||||||
|
throw new TransformationFailedException('Years beyond 9999 are not supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -343,4 +343,22 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
|
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
|
||||||
$transformer->reverseTransform('1789-07-14');
|
$transformer->reverseTransform('1789-07-14');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
|
*/
|
||||||
|
public function testReverseTransformFiveDigitYears()
|
||||||
|
{
|
||||||
|
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd');
|
||||||
|
$transformer->reverseTransform('20107-03-21');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
|
*/
|
||||||
|
public function testReverseTransformFiveDigitYearsWithTimestamp()
|
||||||
|
{
|
||||||
|
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, null, \IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss');
|
||||||
|
$transformer->reverseTransform('20107-03-21 12:34:56');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user