Skip to content

Verify that timestrings can be parsed #3051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
Changes from all commits
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
18 changes: 18 additions & 0 deletions webapp/src/Entity/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,12 @@
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
Expand All @@ -1272,6 +1278,18 @@
#[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;

Check failure on line 1283 in webapp/src/Entity/Contest.php

View workflow job for this annotation

GitHub Actions / phpcs

Inline control structures are not allowed
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
Expand Down
Loading