Skip to content

Commit

Permalink
minor #497 Various fixes and removed deprecations (alexandre-daubois)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolas-grekas committed Sep 18, 2024
2 parents 731f6e1 + 12cbaa2 commit 0ed2048
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 48 deletions.
26 changes: 0 additions & 26 deletions src/Iconv/Iconv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions src/Iconv/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
6 changes: 1 addition & 5 deletions src/Iconv/bootstrap80.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
1 change: 0 additions & 1 deletion src/Util/TestListenerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 1 addition & 6 deletions tests/Iconv/IconvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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('한국어'));
}

/**
Expand Down
16 changes: 12 additions & 4 deletions tests/Mbstring/MbstringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,21 @@ public function testInternalEncodingWithInvalidEncoding()
*/
public function testConvertEncoding()
{
$this->assertSame(utf8_decode('déjà'), mb_convert_encoding('déjà', 'Windows-1252'));
$this->assertSame(iconv('UTF-8', 'ISO-8859-1', 'déjà'), mb_convert_encoding('déjà', 'Windows-1252'));
$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 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('&#23455;<&>d&eacute;j&agrave;', 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&eacute;j&#224;', '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']));
}

/**
Expand Down Expand Up @@ -567,7 +575,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'));
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Php81/Php81Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function testArrayIsList()

/**
* @requires extension mysqli
* @group legacy
*/
public function testMysqliRefreshReplicaDefined()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Tim Düsterhus <duesterhus@woltlab.com>
*/
class SensitiveParameterValueTest extends TestCase
class SensitiveParameterValuePolyfillTest extends TestCase
{
public static function sensitiveParameterValueProvider()
{
Expand Down

0 comments on commit 0ed2048

Please sign in to comment.