merged branch ondrowan/2.0 (PR #2614)
Commits -------2582fcb
Added tests for string fix in DateTimeToArrayTransformer (8351a11286
).8351a11
Added check for array fields to be integers in reverseTransform method. This prevents checkdate from getting strings as arguments and throwing incorrect ErrorException when submitting form with malformed (string) data in, for example, Date field. #2609 Discussion ---------- Fix for #2609 Second take for fix for #2609, hope it's ok now. Tests are failing without my fix and passing with it.
This commit is contained in:
commit
7475a3924c
@ -142,6 +142,10 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
||||
));
|
||||
}
|
||||
|
||||
if (preg_match( '/^\d*$/', $value['month'] . $value['day'] . $value['year']) === 0) {
|
||||
throw new TransformationFailedException('This is an invalid date');
|
||||
}
|
||||
|
||||
if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) {
|
||||
throw new TransformationFailedException('This is an invalid date');
|
||||
}
|
||||
|
@ -463,4 +463,52 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringDay()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => '2010',
|
||||
'month' => '2',
|
||||
'day' => 'bazinga',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringMonth()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => '2010',
|
||||
'month' => 'bazinga',
|
||||
'day' => '31',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testReverseTransformWithStringYear()
|
||||
{
|
||||
$transformer = new DateTimeToArrayTransformer();
|
||||
$transformer->reverseTransform(array(
|
||||
'year' => 'bazinga',
|
||||
'month' => '2',
|
||||
'day' => '31',
|
||||
'hour' => '4',
|
||||
'minute' => '5',
|
||||
'second' => '6',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user