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

Commit

Permalink
Handle the third argument of mb_convert_encoding() being an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer authored and nicolas-grekas committed Oct 14, 2015
1 parent 1bd4a8a commit 5b09e07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 5b09e07

Please sign in to comment.