mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Related to Issue #3741 - Incorrect encoding of a plugin language file could cause json encoding to fail.
This commit is contained in:
@@ -572,7 +572,16 @@ class e_array {
|
||||
|
||||
if($mode === 'json')
|
||||
{
|
||||
return json_encode($ArrayData, JSON_PRETTY_PRINT);
|
||||
//todo discuss - move to e_parse::toJSON() ?
|
||||
$encoded = json_encode($ArrayData, JSON_PRETTY_PRINT);
|
||||
if(json_last_error() === JSON_ERROR_UTF8)
|
||||
{
|
||||
$ArrayData = e107::getParser()->toUTF8($ArrayData);
|
||||
$encoded = json_encode($ArrayData, JSON_PRETTY_PRINT);
|
||||
//todo log
|
||||
}
|
||||
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
$Array = var_export($ArrayData, true);
|
||||
@@ -586,6 +595,8 @@ class e_array {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @DEPRECATED - Backwards Compatible. Use e107::serialize() instead;
|
||||
* @param array $ArrayData array to be stored
|
||||
@@ -628,7 +639,7 @@ class e_array {
|
||||
*
|
||||
* @param string $systemLocationFile relative to e_SYSTEM file path (without the extension)
|
||||
* @param string $extension [optional] file extension, default is 'php'
|
||||
* @return array or false when file not found (or on error)
|
||||
* @return array|false false when file not found (or on error)
|
||||
*/
|
||||
public function load($systemLocationFile, $extension = 'php')
|
||||
{
|
||||
@@ -650,7 +661,7 @@ class e_array {
|
||||
*
|
||||
* @param string $systemLocationFile relative to e_SYSTEM file path (without the extension)
|
||||
* @param string $extension [optional] file extension, default is 'php'
|
||||
* @return array or false when file not found (or on error)
|
||||
* @return array|false when file not found (or on error)
|
||||
*/
|
||||
public function store($array, $systemLocationFile, $extension = 'php')
|
||||
{
|
||||
|
@@ -2120,7 +2120,36 @@ class e_parse extends e_parser
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $mixed
|
||||
* @return array|false|string
|
||||
*/
|
||||
public function toUTF8($mixed)
|
||||
{
|
||||
|
||||
if(is_array($mixed))
|
||||
{
|
||||
foreach($mixed as $k => $v)
|
||||
{
|
||||
unset($mixed[$k]);
|
||||
$mixed[$this->toUTF8($k)] = $this->toUTF8($v);
|
||||
}
|
||||
}
|
||||
elseif(is_object($mixed))
|
||||
{
|
||||
$objVars = get_object_vars($mixed);
|
||||
foreach($objVars as $key => $value)
|
||||
{
|
||||
$mixed->$key = $this->toUTF8($value);
|
||||
}
|
||||
}
|
||||
elseif(is_string($mixed))
|
||||
{
|
||||
return iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($mixed));
|
||||
}
|
||||
|
||||
return $mixed;
|
||||
}
|
||||
|
||||
|
||||
function toASCII($text)
|
||||
|
@@ -759,6 +759,13 @@ class e_plugin
|
||||
|
||||
$cacheSet = e107::serialize($arr,'json');
|
||||
|
||||
if(empty($cacheSet))
|
||||
{
|
||||
$error = json_last_error_msg();
|
||||
e107::getMessage()->addDebug("Plugin Cache JSON encoding is failing! (".__METHOD__.") Line: ".__LINE__);
|
||||
e107::getMessage()->addDebug("JSON Error: ".$error);
|
||||
}
|
||||
|
||||
e107::getCache()->set($cacheTag,$cacheSet,true,true,true);
|
||||
|
||||
$this->_data = $arr;
|
||||
|
@@ -108,16 +108,15 @@ $data = array (
|
||||
$this->assertArrayHasKey('TITLE', $actual);
|
||||
|
||||
|
||||
// case sitePrefs
|
||||
// $string_6 = $this->getSitePrefExample();
|
||||
// $actual = $this->arrObj->unserialize($string_6);
|
||||
|
||||
|
||||
$tests = array(
|
||||
0 => array('string' => $this->getSitePrefExample(),
|
||||
0 => array(
|
||||
'string' => $this->getSitePrefExample(),
|
||||
'expected' => array('email_password' => '$2y$10$IpizFx.gp5USl98SLXwwbeod3SYF3M3raAQX0y01ETexzoutvdyWW' )
|
||||
),
|
||||
|
||||
1 => array(
|
||||
'string' => "{\n \"hello\": \"h\u00e9ll\u00f2 w\u00f2rld\"\n}",
|
||||
'expected' => array('hello'=>'héllò wòrld')
|
||||
),
|
||||
|
||||
|
||||
);
|
||||
@@ -167,5 +166,13 @@ $data = array (
|
||||
$expected5 = "{\n \"hello\": \"world\"\n}";
|
||||
$this->assertEquals($expected5,$result5);
|
||||
|
||||
$pref6 = array('hello'=> mb_convert_encoding('héllò wòrld', 'ISO-8859-1'));
|
||||
$result6 = $this->arrObj->serialize($pref6,'json');
|
||||
$expected6 = "{\n \"hello\": \"h\u00e9ll\u00f2 w\u00f2rld\"\n}";
|
||||
|
||||
$this->assertEquals($expected6,$result6);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user