From b90a23564909c6b0e6d46790cbcbbd4aeef888ef Mon Sep 17 00:00:00 2001 From: MCJ Vasseur <14887731+vmcj@users.noreply.github.com> Date: Wed, 6 Aug 2025 19:02:21 +0200 Subject: [PATCH] Verify that timestrings can be parsed In case of "unknown" timezones we would silently set the starttime to 0 but leave the startTimeString so the user would not be aware that the starttime is set to a completely different value. --- webapp/src/Entity/Contest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/webapp/src/Entity/Contest.php b/webapp/src/Entity/Contest.php index 03a7207594..2721df7a06 100644 --- a/webapp/src/Entity/Contest.php +++ b/webapp/src/Entity/Contest.php @@ -1260,6 +1260,12 @@ public function getFreezeData(): FreezeData return new FreezeData($this); } + public function checkValidTimeString(string $timeString): void { + if (preg_match("/^[+-]?\d+:\d\d(:\d\d(\.\d{1,6})?)?$/", $timeString) !== 1) { + $date = new DateTime($timeString); + } + } + #[ORM\PrePersist] #[ORM\PreUpdate] public function updateTimes(): void @@ -1272,6 +1278,18 @@ public function updateTimes(): void #[Assert\Callback] public function validate(ExecutionContextInterface $context): void { + foreach (['Activate', 'Deactivate', 'Start', 'End', 'Freeze', 'Unfreeze'] as $timeString) { + $tmpValue = $this->{'get' . $timeString . 'timeString'}(); + if ($tmpValue === null) continue; + try { + $this->checkValidTimeString($tmpValue); + } catch (Exception $e) { + $context + ->buildViolation("Can't parse this time:" . $e->getMessage()) + ->atPath(strtolower($timeString) . "timeString") + ->addViolation(); + } + }; $this->updateTimes(); if (Utils::difftime((float)$this->getEndtime(), (float)$this->getStarttime(true)) <= 0) { $context