Skip to content

Commit

Permalink
Merge pull request #47 from nook24/utf8
Browse files Browse the repository at this point in the history
Try to convert non UTF-8 into UTF-8
  • Loading branch information
nook24 authored Sep 26, 2019
2 parents 5f0a39e + 917e00c commit d97b63a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ Check the documentation for the [migration guide](https://statusengine.org/getti
- PHP7.2

## Changelog
**2.2.1**
- Try to convert non UTF-8 characters into UTF-8

**2.2.0**
- Restart dead childs in case of database errors [#44](https://github.com/nook24/statusengine/pull/44)
- Fix restart through systemd
Expand Down
23 changes: 22 additions & 1 deletion cakephp/app/Console/Command/StatusengineLegacyShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,30 @@ protected function checkObject(array $data) {
**/
protected function getJobPayload(GearmanJob $job)
{
$payload = json_decode($job->workload());
$workload = $job->workload();
$payload = json_decode($workload);
$error = json_last_error();

if($error === JSON_ERROR_UTF8){
//Try to detect charset and retry to json_decode

$enclist = [
'UTF-8',
'ISO-8859-15',
'ISO-8859-1', /*'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10',
'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15',*/ 'ISO-8859-16',
'Windows-1251', 'Windows-1252', 'Windows-1254',
'ASCII'
];

$detectEncoding = mb_detect_encoding($workload, $enclist);

$workload = iconv($detectEncoding."//TRANSLIT//IGNORE", "UTF-8", $workload);
$payload = json_decode($workload);
$error = json_last_error();
}

// parsing error
if ($error != JSON_ERROR_NONE) {
if (function_exists('json_last_error_msg')) {
Expand Down

0 comments on commit d97b63a

Please sign in to comment.