Skip to content

Commit ec24f68

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Console] Fixed boxed table style with colspan parse numbers terminated with decimal separator fail reverse transforming invalid RFC 3339 dates
2 parents b5ad792 + 98d78f4 commit ec24f68

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function reverseTransform($rfc3339)
6868
return;
6969
}
7070

71+
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})T\d{2}:\d{2}(?::\d{2})?(?:\.\d)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))$/', $rfc3339, $matches)) {
72+
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $rfc3339));
73+
}
74+
7175
try {
7276
$dateTime = new \DateTime($rfc3339);
7377
} catch (\Exception $e) {
@@ -78,10 +82,8 @@ public function reverseTransform($rfc3339)
7882
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
7983
}
8084

81-
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {
82-
if (!checkdate($matches[2], $matches[3], $matches[1])) {
83-
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
84-
}
85+
if (!checkdate($matches[2], $matches[3], $matches[1])) {
86+
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
8587
}
8688

8789
return $dateTime;

Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,25 @@ public function testReverseTransformWithNonExistingDate()
133133
}
134134

135135
/**
136+
* @dataProvider invalidDateStringProvider
136137
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
137138
*/
138-
public function testReverseTransformExpectsValidDateString()
139+
public function testReverseTransformExpectsValidDateString($date)
139140
{
140141
$transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC');
141142

142-
$transformer->reverseTransform('2010-2010-2010');
143+
$transformer->reverseTransform($date);
144+
}
145+
146+
public function invalidDateStringProvider()
147+
{
148+
return array(
149+
'invalid month' => array('2010-2010-01'),
150+
'invalid day' => array('2010-10-2010'),
151+
'no date' => array('x'),
152+
'cookie format' => array('Saturday, 01-May-2010 04:05:00 Z'),
153+
'RFC 822 format' => array('Sat, 01 May 10 04:05:00 +0000'),
154+
'RSS format' => array('Sat, 01 May 2010 04:05:00 +0000'),
155+
);
143156
}
144157
}

0 commit comments

Comments
 (0)