Skip to content

Commit d0869f7

Browse files
Various fixes and removed deprecations
1 parent 731f6e1 commit d0869f7

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

src/Iconv/Iconv.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public static function strlen1($s, $encoding = null)
451451
return false;
452452
}
453453

454-
return \strlen(utf8_decode($s));
454+
return \strlen(self::utf8Decode($s));
455455
}
456456

457457
public static function strlen2($s, $encoding = null)
@@ -741,4 +741,34 @@ private static function getData($file)
741741

742742
return false;
743743
}
744+
745+
private static function utf8Decode($s)
746+
{
747+
$s = (string) $s;
748+
$len = \strlen($s);
749+
750+
for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
751+
switch ($s[$i] & "\xF0") {
752+
case "\xC0":
753+
case "\xD0":
754+
$c = (\ord($s[$i] & "\x1F") << 6) | \ord($s[++$i] & "\x3F");
755+
$s[$j] = $c < 256 ? \chr($c) : '?';
756+
break;
757+
758+
case "\xF0":
759+
++$i;
760+
// no break
761+
762+
case "\xE0":
763+
$s[$j] = '?';
764+
$i += 2;
765+
break;
766+
767+
default:
768+
$s[$j] = $s[$i];
769+
}
770+
}
771+
772+
return substr($s, 0, $j);
773+
}
744774
}

src/Intl/Idn/bootstrap80.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
}
119119

120120
if (!function_exists('idn_to_ascii')) {
121-
function idn_to_ascii(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_ascii((string) $domain, (int) $flags, (int) $variant, $idna_info); }
121+
function idn_to_ascii(string $domain, int $flags = IDNA_DEFAULT, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); }
122122
}
123123
if (!function_exists('idn_to_utf8')) {
124-
function idn_to_utf8(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_utf8((string) $domain, (int) $flags, (int) $variant, $idna_info); }
124+
function idn_to_utf8(string $domain, int $flags = IDNA_DEFAULT, int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); }
125125
}

src/Util/TestListenerTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ function {$f['name']}{$f['signature']}
131131

132132
$map = [
133133
'?' => '',
134-
'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0',
135134
'array|string|null $string' => 'array|string $string',
136135
'array|string|null $from_encoding = null' => 'array|string|null $from_encoding = null',
137136
'array|string|null $from_encoding' => 'array|string $from_encoding',

tests/Iconv/IconvTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testIconv()
2929
$this->assertFalse(@iconv('UTF-8', 'ISO-8859-1', 'nœud'));
3030
$this->assertSame('nud', iconv('UTF-8', 'ISO-8859-1//IGNORE', 'nœud'));
3131

32-
$this->assertSame(utf8_decode('déjà'), iconv('CP1252', 'ISO-8859-1', utf8_decode('déjà')));
32+
$this->assertSame(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), iconv('CP1252', 'ISO-8859-1', mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8')));
3333
$this->assertSame('deja noeud', p::iconv('UTF-8//ignore//IGNORE', 'US-ASCII//TRANSLIT//IGNORE//translit', 'déjà nœud'));
3434

3535
$this->assertSame('4', iconv('UTF-8', 'UTF-8', 4));

tests/Mbstring/MbstringTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,21 @@ public function testInternalEncodingWithInvalidEncoding()
6868
*/
6969
public function testConvertEncoding()
7070
{
71-
$this->assertSame(utf8_decode('déjà'), mb_convert_encoding('déjà', 'Windows-1252'));
71+
$this->assertSame(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), mb_convert_encoding('déjà', 'Windows-1252'));
72+
$this->assertSame('déjà', mb_convert_encoding(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), 'Utf-8', 'ASCII,ISO-2022-JP,UTF-8,ISO-8859-1'));
73+
$this->assertSame('déjà', mb_convert_encoding(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), 'Utf-8', ['ASCII', 'ISO-2022-JP', 'UTF-8', 'ISO-8859-1']));
74+
}
75+
76+
/**
77+
* @group legacy
78+
*/
79+
public function testConvertLegacyEncoding()
80+
{
81+
// handling base64 and html entities with mb_convert_encoding is deprecated in PHP 8.2
7282
$this->assertSame(base64_encode('déjà'), mb_convert_encoding('déjà', 'Base64'));
7383
$this->assertSame('&#23455;<&>d&eacute;j&agrave;', mb_convert_encoding('実<&>déjà', 'Html-entities'));
7484
$this->assertSame('déjà', mb_convert_encoding(base64_encode('déjà'), 'Utf-8', 'Base64'));
7585
$this->assertSame('déjà', mb_convert_encoding('d&eacute;j&#224;', 'Utf-8', 'Html-entities'));
76-
$this->assertSame('déjà', mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', 'ASCII,ISO-2022-JP,UTF-8,ISO-8859-1'));
77-
$this->assertSame('déjà', mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', ['ASCII', 'ISO-2022-JP', 'UTF-8', 'ISO-8859-1']));
7886
}
7987

8088
/**
@@ -567,7 +575,7 @@ public function testStrwidth()
567575
{
568576
$this->assertSame(3, mb_strwidth("\000", 'UTF-8'));
569577
$this->assertSame(4, mb_strwidth('déjà', 'UTF-8'));
570-
$this->assertSame(4, mb_strwidth(utf8_decode('déjà'), 'CP1252'));
578+
$this->assertSame(4, mb_strwidth(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), 'CP1252'));
571579
}
572580

573581
/**

tests/Php81/Php81Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testArrayIsList()
3434

3535
/**
3636
* @requires extension mysqli
37+
* @requires PHP < 8.4
3738
*/
3839
public function testMysqliRefreshReplicaDefined()
3940
{

0 commit comments

Comments
 (0)