diff --git a/src/Utility/Model/EnumParser.php b/src/Utility/Model/EnumParser.php index 92f10080..df3ed5dc 100644 --- a/src/Utility/Model/EnumParser.php +++ b/src/Utility/Model/EnumParser.php @@ -3,6 +3,8 @@ namespace Bake\Utility\Model; +use InvalidArgumentException; + enum EnumParser { /** @@ -28,6 +30,13 @@ public static function parseCases(?string $casesString, bool $int): array $value = $k; } + if (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $case)) { + throw new InvalidArgumentException(sprintf('`%s` is not a valid enum case', $case)); + } + if (is_string($value) && str_contains($value, '\'')) { + throw new InvalidArgumentException(sprintf('`%s` value cannot contain `\'` character', $case)); + } + $definition[$case] = $int ? (int)$value : $value; }