Skip to content

Commit 0ed2048

Browse files
minor #497 Various fixes and removed deprecations (alexandre-daubois)
This PR was merged into the 1.x branch. Discussion ---------- Various fixes and removed deprecations First batch of fixes with the "new" CI. Commits ------- 12cbaa2 Various fixes and removed deprecations
2 parents 731f6e1 + 12cbaa2 commit 0ed2048

File tree

8 files changed

+17
-48
lines changed

8 files changed

+17
-48
lines changed

src/Iconv/Iconv.php

-26
Original file line numberDiff line numberDiff line change
@@ -429,32 +429,6 @@ public static function iconv_mime_encode($fieldName, $fieldValue, $pref = null)
429429
}
430430

431431
public static function iconv_strlen($s, $encoding = null)
432-
{
433-
static $hasXml = null;
434-
if (null === $hasXml) {
435-
$hasXml = \extension_loaded('xml');
436-
}
437-
438-
if ($hasXml) {
439-
return self::strlen1($s, $encoding);
440-
}
441-
442-
return self::strlen2($s, $encoding);
443-
}
444-
445-
public static function strlen1($s, $encoding = null)
446-
{
447-
if (null === $encoding) {
448-
$encoding = self::$internalEncoding;
449-
}
450-
if (0 !== stripos($encoding, 'utf-8') && false === $s = self::iconv($encoding, 'utf-8', $s)) {
451-
return false;
452-
}
453-
454-
return \strlen(utf8_decode($s));
455-
}
456-
457-
public static function strlen2($s, $encoding = null)
458432
{
459433
if (null === $encoding) {
460434
$encoding = self::$internalEncoding;

src/Iconv/bootstrap.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEnc
6666
}
6767
} else {
6868
if (!function_exists('iconv_strlen')) {
69-
if (extension_loaded('xml')) {
70-
function iconv_strlen($string, $encoding = null) { return p\Iconv::strlen1($string, $encoding); }
71-
} else {
72-
function iconv_strlen($string, $encoding = null) { return p\Iconv::strlen2($string, $encoding); }
73-
}
69+
function iconv_strlen($string, $encoding = null) { return p\Iconv::iconv_strlen($string, $encoding); }
7470
}
7571

7672
if (!function_exists('iconv_strpos')) {

src/Iconv/bootstrap80.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEnc
5858
}
5959
} else {
6060
if (!function_exists('iconv_strlen')) {
61-
if (extension_loaded('xml')) {
62-
function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen1((string) $string, $encoding); }
63-
} else {
64-
function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::strlen2((string) $string, $encoding); }
65-
}
61+
function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::iconv_strlen((string) $string, $encoding); }
6662
}
6763

6864
if (!function_exists('iconv_strpos')) {

src/Util/TestListenerTrait.php

-1
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

+1-6
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));
@@ -38,16 +38,11 @@ public function testIconv()
3838

3939
/**
4040
* @covers \Symfony\Polyfill\Iconv\Iconv::iconv_strlen
41-
* @covers \Symfony\Polyfill\Iconv\Iconv::strlen1
42-
* @covers \Symfony\Polyfill\Iconv\Iconv::strlen2
4341
*/
4442
public function testIconvStrlen()
4543
{
4644
$this->assertSame(4, iconv_strlen('déjà', 'UTF-8'));
4745
$this->assertSame(3, iconv_strlen('한국어', 'UTF-8'));
48-
49-
$this->assertSame(4, p::strlen2('déjà'));
50-
$this->assertSame(3, p::strlen2('한국어'));
5146
}
5247

5348
/**

tests/Mbstring/MbstringTest.php

+12-4
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(iconv('UTF-8', 'ISO-8859-1', 'déjà'), 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

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testArrayIsList()
3434

3535
/**
3636
* @requires extension mysqli
37+
* @group legacy
3738
*/
3839
public function testMysqliRefreshReplicaDefined()
3940
{

tests/Php82/SensitiveParameterValueTest.php renamed to tests/Php82/SensitiveParameterValuePolyfillTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* @author Tim Düsterhus <[email protected]>
1919
*/
20-
class SensitiveParameterValueTest extends TestCase
20+
class SensitiveParameterValuePolyfillTest extends TestCase
2121
{
2222
public static function sensitiveParameterValueProvider()
2323
{

0 commit comments

Comments
 (0)