From d51e0e8642bb344e4752cd7307415d50f5834c6f Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Mon, 5 Aug 2024 17:17:30 +0200 Subject: [PATCH] Finetune PCRE version check --- src/Validator/Constraints/BannedScripts.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Validator/Constraints/BannedScripts.php b/src/Validator/Constraints/BannedScripts.php index fd3620e..409e5a8 100644 --- a/src/Validator/Constraints/BannedScripts.php +++ b/src/Validator/Constraints/BannedScripts.php @@ -46,7 +46,8 @@ public function __construct( public function getCharacterClass(): string { if (!isset($this->characterClass)) { - if (version_compare(static::MINIMUM_PCRE_VERSION, PCRE_VERSION) > 0) { + // Some distros use exotic version strings like "10.40 2022-04-14" which version_compare can't handle, hence the extra check + if (version_compare(static::MINIMUM_PCRE_VERSION, PCRE_VERSION) > 0 && strtok(PCRE_VERSION, ' ') !== static::MINIMUM_PCRE_VERSION) { 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, static::MINIMUM_PCRE_VERSION)); } $this->characterClass = sprintf('[%s]', implode('', array_map(fn (Script $script) => sprintf('\\p{%s}', $script->value), $this->scripts)));