Skip to content

Commit

Permalink
Keep for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 29, 2024
1 parent 8b1d826 commit dc0198b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Sqids.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ class Sqids implements SqidsInterface

protected MathInterface $math;

protected ?string $blocklist = null;
protected ?string $blocklistRegex = null;

/** @throws \InvalidArgumentException */
/** @throws InvalidArgumentException */
public function __construct(
protected string $alphabet = self::DEFAULT_ALPHABET,
protected int $minLength = self::DEFAULT_MIN_LENGTH,
array $blocklist = self::DEFAULT_BLOCKLIST,
protected array $blocklist = self::DEFAULT_BLOCKLIST,
) {
$this->math = $this->getMathExtension();

Expand Down Expand Up @@ -268,15 +268,14 @@ public function __construct(
);
}

// Filter out blocklist words that are shorter than 3 characters or contain non-alphabet characters
$filteredBlocklist = [];
foreach ($blocklist as $word) {
if (strlen((string) $word) >= 3) {
$filteredBlocklist[] = strtr(preg_quote((string) $word, '/'), self::LEET);
}
}
if ($filteredBlocklist) {
$this->blocklist = '/(' . implode('|', $filteredBlocklist) . ')/i';
$this->blocklistRegex = '/(' . implode('|', $filteredBlocklist) . ')/i';
}

$this->alphabet = $this->shuffle($alphabet);
Expand Down Expand Up @@ -454,7 +453,7 @@ protected function toNumber(string $id, string $alphabet): int

protected function isBlockedId(string $id): bool
{
return $this->blocklist !== null && preg_match($this->blocklist, $id);
return $this->blocklistRegex !== null && preg_match($this->blocklistRegex, $id);
}

protected static function maxValue(): int
Expand Down

0 comments on commit dc0198b

Please sign in to comment.