Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f06f15

Browse filesBrowse files
committed
Add stricter checking for valid date time string
1 parent 253d0a6 commit 4f06f15
Copy full SHA for 4f06f15

File tree

Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5DateTimeLocalTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5DateTimeLocalTransformer.php
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public function reverseTransform($dateTimeLocal)
7676
return;
7777
}
7878

79+
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
80+
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
81+
}
82+
7983
try {
8084
$dateTime = new \DateTime($dateTimeLocal, new \DateTimeZone($this->outputTimezone));
8185
} catch (\Exception $e) {
@@ -86,10 +90,8 @@ public function reverseTransform($dateTimeLocal)
8690
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
8791
}
8892

89-
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $dateTimeLocal, $m)) {
90-
if (!checkdate($m[2], $m[3], $m[1])) {
91-
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $m[1], $m[2], $m[3]));
92-
}
93+
if (!checkdate($matches[2], $matches[3], $matches[1])) {
94+
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
9395
}
9496

9597
return $dateTime;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.