Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Handle the third argument of mb_convert_encoding() being an array #52

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Patchwork/PHP/Shim/Mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public static function mb_convert_encoding($s, $to_encoding, $from_encoding = IN
{
INF === $from_encoding and $from_encoding = self::$internal_encoding;

if (is_array($from_encoding) || false !== strpos($from_encoding, ',')) {
$from_encoding = self::mb_detect_encoding($s, $from_encoding);
}

$from_encoding = strtolower($from_encoding);
$to_encoding = strtolower($to_encoding);

Expand Down Expand Up @@ -271,7 +275,9 @@ public static function mb_detect_encoding($str, $encoding_list = INF, $strict =
break;

default:
return strncmp($enc, 'ISO-8859-', 9) ? false : $enc;
if (0 === strncmp($enc, 'ISO-8859-', 9)) {
return $enc;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Patchwork/Tests/PHP/Shim/MbstringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function testmb_convert_encoding()
$this->assertSame('&#23455;<&>d&eacute;j&agrave;', p::mb_convert_encoding('実<&>déjà', 'Html-entities'));
$this->assertSame('déjà', p::mb_convert_encoding(base64_encode('déjà'), 'Utf-8', 'Base64'));
$this->assertSame('déjà', p::mb_convert_encoding('d&eacute;j&#224;', 'Utf-8', 'Html-entities'));
$this->assertSame('déjà', p::mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', 'ASCII,ISO-2022-JP,UTF-8,ISO-8859-1'));
$this->assertSame('déjà', p::mb_convert_encoding(utf8_decode('déjà'), 'Utf-8', array('ASCII', 'ISO-2022-JP', 'UTF-8', 'ISO-8859-1')));
}

/**
Expand Down