Skip to content

Commit b38aab9

Browse files
committed
Stricter validation
1 parent f5a3766 commit b38aab9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Utility/Model/EnumParser.php

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Bake\Utility\Model;
55

6+
use InvalidArgumentException;
7+
68
enum EnumParser
79
{
810
/**
@@ -28,6 +30,13 @@ public static function parseCases(?string $casesString, bool $int): array
2830
$value = $k;
2931
}
3032

33+
if (!preg_match('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/', $case)) {
34+
throw new InvalidArgumentException(sprintf('`%s` is not a valid enum case', $case));
35+
}
36+
if (is_string($value) && str_contains($value, '\'')) {
37+
throw new InvalidArgumentException(sprintf('`%s` value cannot contain `\'` character', $case));
38+
}
39+
3140
$definition[$case] = $int ? (int)$value : $value;
3241
}
3342

0 commit comments

Comments
 (0)