Skip to content

Commit

Permalink
Stricter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 31, 2023
1 parent f5a3766 commit b38aab9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Utility/Model/EnumParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Bake\Utility\Model;

use InvalidArgumentException;

enum EnumParser
{
/**
Expand All @@ -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));

Check warning on line 34 in src/Utility/Model/EnumParser.php

View check run for this annotation

Codecov / codecov/patch

src/Utility/Model/EnumParser.php#L34

Added line #L34 was not covered by tests
}
if (is_string($value) && str_contains($value, '\'')) {
throw new InvalidArgumentException(sprintf('`%s` value cannot contain `\'` character', $case));

Check warning on line 37 in src/Utility/Model/EnumParser.php

View check run for this annotation

Codecov / codecov/patch

src/Utility/Model/EnumParser.php#L37

Added line #L37 was not covered by tests
}

$definition[$case] = $int ? (int)$value : $value;
}

Expand Down

0 comments on commit b38aab9

Please sign in to comment.