Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add stricter checking for valid date time string
  • Loading branch information
mcfedr committed Sep 15, 2018
commit 4f06f1524d41497b5c07a302c2457410ece9a523
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function reverseTransform($dateTimeLocal)
return;
}

if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $dateTimeLocal));
}

try {
$dateTime = new \DateTime($dateTimeLocal, new \DateTimeZone($this->outputTimezone));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check the format of the submitted date first to avoid issues like #28455 (the approach could IMO be similar to what I propose in #28466).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I've added something similar here.

} catch (\Exception $e) {
Expand All @@ -86,10 +90,8 @@ public function reverseTransform($dateTimeLocal)
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
}

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

return $dateTime;
Expand Down