diff --git a/src/Validator/Constraints/BannedScripts.php b/src/Validator/Constraints/BannedScripts.php index eddd4f0..32ae78e 100644 --- a/src/Validator/Constraints/BannedScripts.php +++ b/src/Validator/Constraints/BannedScripts.php @@ -18,6 +18,8 @@ #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class BannedScripts extends AntiSpamConstraint { + public const MINIMUM_PCRE_VERSION = '10.40'; + /** @var Script[] */ public array $scripts; @@ -44,6 +46,10 @@ public function __construct( public function getCharacterClass(): string { if (!isset($this->characterClass)) { + /* @phpstan-ignore-next-line @infection-ignore-all impossible to test this check, and phpstan thinks it's a constant check */ + if (version_compare(self::MINIMUM_PCRE_VERSION, PCRE_VERSION) > 0) { + throw new \LogicException(sprintf('PHP is using PCRE version %s but requires at least version %s to detect banned scripts. Update your PHP installation and/or operating system.', PCRE_VERSION, self::MINIMUM_PCRE_VERSION)); // @codeCoverageIgnore + } $this->characterClass = sprintf('[%s]', implode('', array_map(fn (Script $script) => sprintf('\\p{%s}', $script->value), $this->scripts))); }