Skip to content

Commit 65af5fe

Browse files
committed
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.
1 parent 540a41e commit 65af5fe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

webapp/src/Entity/Contest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,12 @@ public function getFreezeData(): FreezeData
12601260
return new FreezeData($this);
12611261
}
12621262

1263+
public function checkValidTimeString(string $timeString): void {
1264+
if (preg_match("/^[+-]?\d+:\d\d(:\d\d(\.\d{1,6})?)?$/", $timeString) !== 1) {
1265+
$date = new DateTime($timeString);
1266+
}
1267+
}
1268+
12631269
#[ORM\PrePersist]
12641270
#[ORM\PreUpdate]
12651271
public function updateTimes(): void
@@ -1272,6 +1278,18 @@ public function updateTimes(): void
12721278
#[Assert\Callback]
12731279
public function validate(ExecutionContextInterface $context): void
12741280
{
1281+
foreach (['Activate', 'Deactivate', 'Start', 'End', 'Freeze', 'Unfreeze'] as $timeString) {
1282+
$tmpValue = $this->{'get' . $timeString . 'timeString'}();
1283+
if ($tmpValue === null) continue;
1284+
try {
1285+
$this->checkValidTimeString($tmpValue);
1286+
} catch (Exception $e) {
1287+
$context
1288+
->buildViolation("Can't parse this time:" . $e->getMessage())
1289+
->atPath(strtolower($timeString) . "timeString")
1290+
->addViolation();
1291+
}
1292+
};
12751293
$this->updateTimes();
12761294
if (Utils::difftime((float)$this->getEndtime(), (float)$this->getStarttime(true)) <= 0) {
12771295
$context

0 commit comments

Comments
 (0)