Skip to content

Commit a71c641

Browse files
committed
Allow for both hexcolors with alpha as shorthand
1 parent 65af5fe commit a71c641

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

webapp/src/Entity/ContestProblem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function validate(ExecutionContextInterface $context): void
261261
{
262262
if ($this->getColor() && Utils::convertToHex($this->getColor()) === null) {
263263
$context
264-
->buildViolation('This is not a valid color')
264+
->buildViolation('This is not a valid color.')
265265
->atPath('color')
266266
->addViolation();
267267
}

webapp/src/Utils/Utils.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ public static function timeStringDiff(string $time1, string $time2): string
290290
*/
291291
public static function convertToHex(string $color): ?string
292292
{
293-
if (preg_match('/^#[[:xdigit:]]{3,6}$/', $color)) {
293+
if (preg_match('/^#[[:xdigit:]]{3,4}$/', $color) ||
294+
preg_match('/^#[[:xdigit:]]{6}$/', $color) ||
295+
preg_match('/^#[[:xdigit:]]{8}$/', $color)
296+
) {
294297
return $color;
295298
}
296299

0 commit comments

Comments
 (0)