From d293634f5c40ab7e009158c8dc9a6b4b378d0cde Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 11 Sep 2024 09:34:10 +0200 Subject: [PATCH] Various fixes and removed deprecations --- src/Iconv/Iconv.php | 26 ------------------- src/Iconv/bootstrap.php | 6 +---- src/Iconv/bootstrap80.php | 6 +---- src/Util/TestListenerTrait.php | 1 - tests/Iconv/IconvTest.php | 7 +---- tests/Mbstring/MbstringTest.php | 21 ++++++++++++--- tests/Php81/Php81Test.php | 1 + ...> SensitiveParameterValuePolyfillTest.php} | 2 +- 8 files changed, 23 insertions(+), 47 deletions(-) rename tests/Php82/{SensitiveParameterValueTest.php => SensitiveParameterValuePolyfillTest.php} (96%) diff --git a/src/Iconv/Iconv.php b/src/Iconv/Iconv.php index c17a70dc2..b4421449c 100644 --- a/src/Iconv/Iconv.php +++ b/src/Iconv/Iconv.php @@ -429,32 +429,6 @@ public static function iconv_mime_encode($fieldName, $fieldValue, $pref = null) } public static function iconv_strlen($s, $encoding = null) - { - static $hasXml = null; - if (null === $hasXml) { - $hasXml = \extension_loaded('xml'); - } - - if ($hasXml) { - return self::strlen1($s, $encoding); - } - - return self::strlen2($s, $encoding); - } - - public static function strlen1($s, $encoding = null) - { - if (null === $encoding) { - $encoding = self::$internalEncoding; - } - if (0 !== stripos($encoding, 'utf-8') && false === $s = self::iconv($encoding, 'utf-8', $s)) { - return false; - } - - return \strlen(utf8_decode($s)); - } - - public static function strlen2($s, $encoding = null) { if (null === $encoding) { $encoding = self::$internalEncoding; diff --git a/src/Iconv/bootstrap.php b/src/Iconv/bootstrap.php index c11df3b32..e629531fa 100644 --- a/src/Iconv/bootstrap.php +++ b/src/Iconv/bootstrap.php @@ -66,11 +66,7 @@ function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEnc } } else { if (!function_exists('iconv_strlen')) { - if (extension_loaded('xml')) { - function iconv_strlen($string, $encoding = null) { return p\Iconv::strlen1($string, $encoding); } - } else { - function iconv_strlen($string, $encoding = null) { return p\Iconv::strlen2($string, $encoding); } - } + function iconv_strlen($string, $encoding = null) { return p\Iconv::iconv_strlen($string, $encoding); } } if (!function_exists('iconv_strpos')) { diff --git a/src/Iconv/bootstrap80.php b/src/Iconv/bootstrap80.php index 04b1473b7..2d0f12fdc 100644 --- a/src/Iconv/bootstrap80.php +++ b/src/Iconv/bootstrap80.php @@ -58,11 +58,7 @@ function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEnc } } else { if (!function_exists('iconv_strlen')) { - if (extension_loaded('xml')) { - function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen1((string) $string, $encoding); } - } else { - function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen2((string) $string, $encoding); } - } + function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::iconv_strlen((string) $string, $encoding); } } if (!function_exists('iconv_strpos')) { diff --git a/src/Util/TestListenerTrait.php b/src/Util/TestListenerTrait.php index 58024695c..9527b52bb 100644 --- a/src/Util/TestListenerTrait.php +++ b/src/Util/TestListenerTrait.php @@ -131,7 +131,6 @@ function {$f['name']}{$f['signature']} $map = [ '?' => '', - 'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0', 'array|string|null $string' => 'array|string $string', 'array|string|null $from_encoding = null' => 'array|string|null $from_encoding = null', 'array|string|null $from_encoding' => 'array|string $from_encoding', diff --git a/tests/Iconv/IconvTest.php b/tests/Iconv/IconvTest.php index 214ea36ef..e72b71a1c 100644 --- a/tests/Iconv/IconvTest.php +++ b/tests/Iconv/IconvTest.php @@ -29,7 +29,7 @@ public function testIconv() $this->assertFalse(@iconv('UTF-8', 'ISO-8859-1', 'nœud')); $this->assertSame('nud', iconv('UTF-8', 'ISO-8859-1//IGNORE', 'nœud')); - $this->assertSame(utf8_decode('déjà'), iconv('CP1252', 'ISO-8859-1', utf8_decode('déjà'))); + $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'))); $this->assertSame('deja noeud', p::iconv('UTF-8//ignore//IGNORE', 'US-ASCII//TRANSLIT//IGNORE//translit', 'déjà nœud')); $this->assertSame('4', iconv('UTF-8', 'UTF-8', 4)); @@ -38,16 +38,11 @@ public function testIconv() /** * @covers \Symfony\Polyfill\Iconv\Iconv::iconv_strlen - * @covers \Symfony\Polyfill\Iconv\Iconv::strlen1 - * @covers \Symfony\Polyfill\Iconv\Iconv::strlen2 */ public function testIconvStrlen() { $this->assertSame(4, iconv_strlen('déjà', 'UTF-8')); $this->assertSame(3, iconv_strlen('한국어', 'UTF-8')); - - $this->assertSame(4, p::strlen2('déjà')); - $this->assertSame(3, p::strlen2('한국어')); } /** diff --git a/tests/Mbstring/MbstringTest.php b/tests/Mbstring/MbstringTest.php index bacaf3dbe..610bc6c46 100644 --- a/tests/Mbstring/MbstringTest.php +++ b/tests/Mbstring/MbstringTest.php @@ -67,14 +67,29 @@ public function testInternalEncodingWithInvalidEncoding() * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_convert_encoding */ public function testConvertEncoding() + { + $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')); + $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'])); + } + + /** + * @group legacy + */ + public function testConvertUtf8Encoding() { $this->assertSame(utf8_decode('déjà'), mb_convert_encoding('déjà', 'Windows-1252')); + } + + /** + * @group legacy + */ + public function testConvertLegacyEncoding() + { + // handling base64 and html entities with mb_convert_encoding is deprecated in PHP 8.2 $this->assertSame(base64_encode('déjà'), mb_convert_encoding('déjà', 'Base64')); $this->assertSame('実<&>déjà', mb_convert_encoding('実<&>déjà', 'Html-entities')); $this->assertSame('déjà', mb_convert_encoding(base64_encode('déjà'), 'Utf-8', 'Base64')); $this->assertSame('déjà', mb_convert_encoding('déjà', 'Utf-8', 'Html-entities')); - $this->assertSame('déjà', mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', 'ASCII,ISO-2022-JP,UTF-8,ISO-8859-1')); - $this->assertSame('déjà', mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', ['ASCII', 'ISO-2022-JP', 'UTF-8', 'ISO-8859-1'])); } /** @@ -567,7 +582,7 @@ public function testStrwidth() { $this->assertSame(3, mb_strwidth("\000実", 'UTF-8')); $this->assertSame(4, mb_strwidth('déjà', 'UTF-8')); - $this->assertSame(4, mb_strwidth(utf8_decode('déjà'), 'CP1252')); + $this->assertSame(4, mb_strwidth(mb_convert_encoding('déjà', 'ISO-8859-1', 'UTF-8'), 'CP1252')); } /** diff --git a/tests/Php81/Php81Test.php b/tests/Php81/Php81Test.php index f3764ef92..8047528cd 100644 --- a/tests/Php81/Php81Test.php +++ b/tests/Php81/Php81Test.php @@ -34,6 +34,7 @@ public function testArrayIsList() /** * @requires extension mysqli + * @group legacy */ public function testMysqliRefreshReplicaDefined() { diff --git a/tests/Php82/SensitiveParameterValueTest.php b/tests/Php82/SensitiveParameterValuePolyfillTest.php similarity index 96% rename from tests/Php82/SensitiveParameterValueTest.php rename to tests/Php82/SensitiveParameterValuePolyfillTest.php index 49586d02f..2fdc38c4a 100644 --- a/tests/Php82/SensitiveParameterValueTest.php +++ b/tests/Php82/SensitiveParameterValuePolyfillTest.php @@ -17,7 +17,7 @@ /** * @author Tim Düsterhus */ -class SensitiveParameterValueTest extends TestCase +class SensitiveParameterValuePolyfillTest extends TestCase { public static function sensitiveParameterValueProvider() {