Skip to content

Commit

Permalink
Add runtime check for minimum PCRE version for banned scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Jun 18, 2024
1 parent d36f5ca commit 9432026
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Validator/Constraints/BannedScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)));
}

Expand Down

0 comments on commit 9432026

Please sign in to comment.