Skip to content

Commit

Permalink
Finetune PCRE version check
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Aug 5, 2024
1 parent ccee171 commit d51e0e8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Validator/Constraints/BannedScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down

0 comments on commit d51e0e8

Please sign in to comment.