: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Vendor\TrueBV;
use WPForms\Vendor\TrueBV\Exception\DomainOutOfBoundsException;
use WPForms\Vendor\TrueBV\Exception\LabelOutOfBoundsException;
* Punycode implementation as described in RFC 3492
* @link http://tools.ietf.org/html/rfc3492
* Bootstring parameter values
protected static $encodeTable = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
protected static $decodeTable = array('a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, 'g' => 6, 'h' => 7, 'i' => 8, 'j' => 9, 'k' => 10, 'l' => 11, 'm' => 12, 'n' => 13, 'o' => 14, 'p' => 15, 'q' => 16, 'r' => 17, 's' => 18, 't' => 19, 'u' => 20, 'v' => 21, 'w' => 22, 'x' => 23, 'y' => 24, 'z' => 25, '0' => 26, '1' => 27, '2' => 28, '3' => 29, '4' => 30, '5' => 31, '6' => 32, '7' => 33, '8' => 34, '9' => 35);
* @param string $encoding Character encoding
public function __construct($encoding = 'UTF-8')
$this->encoding = $encoding;
* Encode a domain to its Punycode version
* @param string $input Domain name in Unicode to be encoded
* @return string Punycode representation in ASCII
public function encode($input)
$input = \mb_strtolower($input, $this->encoding);
$parts = \explode('.', $input);
foreach ($parts as &$part) {
$length = \strlen($part);
throw new LabelOutOfBoundsException(\sprintf('The length of any one label is limited to between 1 and 63 octets, but %s given.', $length));
$part = $this->encodePart($part);
$output = \implode('.', $parts);
$length = \strlen($output);
throw new DomainOutOfBoundsException(\sprintf('A full domain name is limited to 255 octets (including the separators), %s given.', $length));
* Encode a part of a domain name, such as tld, to its Punycode version
* @param string $input Part of a domain name
* @return string Punycode representation of a domain part
protected function encodePart($input)
$codePoints = $this->listCodePoints($input);
$bias = static::INITIAL_BIAS;
$h = $b = \count($codePoints['basic']);
foreach ($codePoints['basic'] as $code) {
$output .= $this->codePointToChar($code);
if ($input === $output) {
$output .= static::DELIMITER;
$codePoints['nonBasic'] = \array_unique($codePoints['nonBasic']);
\sort($codePoints['nonBasic']);
$length = \mb_strlen($input, $this->encoding);
$m = $codePoints['nonBasic'][$i++];
$delta = $delta + ($m - $n) * ($h + 1);
foreach ($codePoints['all'] as $c) {
if ($c < $n || $c < static::INITIAL_N) {
for ($k = static::BASE;; $k += static::BASE) {
$t = $this->calculateThreshold($k, $bias);
$code = $t + ($q - $t) % (static::BASE - $t);
$output .= static::$encodeTable[$code];
$q = ($q - $t) / (static::BASE - $t);
$output .= static::$encodeTable[$q];
$bias = $this->adapt($delta, $h + 1, $h === $b);
$out = static::PREFIX . $output;
if ($length > 63 || $length < 1) {
throw new LabelOutOfBoundsException(\sprintf('The length of any one label is limited to between 1 and 63 octets, but %s given.', $length));
* Decode a Punycode domain name to its Unicode counterpart
* @param string $input Domain name in Punycode
* @return string Unicode domain name
public function decode($input)
$input = \strtolower($input);
$parts = \explode('.', $input);
foreach ($parts as &$part) {
$length = \strlen($part);
if ($length > 63 || $length < 1) {
throw new LabelOutOfBoundsException(\sprintf('The length of any one label is limited to between 1 and 63 octets, but %s given.', $length));
if (\strpos($part, static::PREFIX) !== 0) {
$part = \substr($part, \strlen(static::PREFIX));
$part = $this->decodePart($part);
$output = \implode('.', $parts);
$length = \strlen($output);
throw new DomainOutOfBoundsException(\sprintf('A full domain name is limited to 255 octets (including the separators), %s given.', $length));
* Decode a part of domain name, such as tld
* @param string $input Part of a domain name
* @return string Unicode domain part
protected function decodePart($input)
$bias = static::INITIAL_BIAS;
$pos = \strrpos($input, static::DELIMITER);
$output = \substr($input, 0, $pos++);
$outputLength = \strlen($output);
$inputLength = \strlen($input);
while ($pos < $inputLength) {
for ($k = static::BASE;; $k += static::BASE) {
$digit = static::$decodeTable[$input[$pos++]];
$t = $this->calculateThreshold($k, $bias);
$w = $w * (static::BASE - $t);
$bias = $this->adapt($i - $oldi, ++$outputLength, $oldi === 0);
$n = $n + (int) ($i / $outputLength);
$output = \mb_substr($output, 0, $i, $this->encoding) . $this->codePointToChar($n) . \mb_substr($output, $i, $outputLength - 1, $this->encoding);
* Calculate the bias threshold to fall between TMIN and TMAX
protected function calculateThreshold($k, $bias)
if ($k <= $bias + static::TMIN) {
} elseif ($k >= $bias + static::TMAX) {
* @param integer $numPoints
* @param boolean $firstTime
protected function adapt($delta, $numPoints, $firstTime)
$delta = (int) ($firstTime ? $delta / static::DAMP : $delta / 2);
$delta += (int) ($delta / $numPoints);
while ($delta > (static::BASE - static::TMIN) * static::TMAX / 2) {
$delta = (int) ($delta / (static::BASE - static::TMIN));
$k = $k + (int) ((static::BASE - static::TMIN + 1) * $delta / ($delta + static::SKEW));
* List code points for a given input
* @return array Multi-dimension array with basic, non-basic and aggregated code points
protected function listCodePoints($input)
$codePoints = array('all' => array(), 'basic' => array(), 'nonBasic' => array());
$length = \mb_strlen($input, $this->encoding);
for ($i = 0; $i < $length; $i++) {
$char = \mb_substr($input, $i, 1, $this->encoding);
$code = $this->charToCodePoint($char);
$codePoints['all'][] = $codePoints['basic'][] = $code;
$codePoints['all'][] = $codePoints['nonBasic'][] = $code;
* Convert a single or multi-byte character to its code point
protected function charToCodePoint($char)
return ($code - 192) * 64 + (\ord($char[1]) - 128);
return ($code - 224) * 4096 + (\ord($char[1]) - 128) * 64 + (\ord($char[2]) - 128);
return ($code - 240) * 262144 + (\ord($char[1]) - 128) * 4096 + (\ord($char[2]) - 128) * 64 + (\ord($char[3]) - 128);
* Convert a code point to its single or multi-byte character
protected function codePointToChar($code)
} elseif ($code <= 0x7ff) {
return \chr(($code >> 6) + 192) . \chr(($code & 63) + 128);
} elseif ($code <= 0xffff) {
return \chr(($code >> 12) + 224) . \chr(($code >> 6 & 63) + 128) . \chr(($code & 63) + 128);
return \chr(($code >> 18) + 240) . \chr(($code >> 12 & 63) + 128) . \chr(($code >> 6 & 63) + 128) . \chr(($code & 63) + 128);