diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2789736fad..5a7a75f2dc 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2013-10-13 Junichi Satoh + + * godmode/alerts/alert_commands.php, include/functions_io.php: Fixed + that unexpected fields descriptions are set when multi-byte characters + are entered. + It is caused by json_encode(). It escapes unicode used by multi-byte + characters. I've created io_json_mb_encode(), replacement of + json_encode() for multi-byte characters. + 2013-10-12 Junichi Satoh * include/help/ja/help_reporting_advanced_tab.php, diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 143d445b67..4847e19be0 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -149,8 +149,8 @@ if ($create_command) { $info_fields .= ' Field'.$i.': ' . $fields_values[$i - 1]; } - $values['fields_values'] = json_encode($fields_values); - $values['fields_descriptions'] = json_encode($fields_descriptions); + $values['fields_values'] = io_json_mb_encode($fields_values); + $values['fields_descriptions'] = io_json_mb_encode($fields_descriptions); $values['description'] = $description; $name_check = db_get_value ('name', 'talert_commands', 'name', $name); @@ -200,8 +200,8 @@ if ($update_command) { $info_fields .= ' Field'.$i.': ' . $fields_values[$i - 1]; } - $values['fields_values'] = json_encode($fields_values); - $values['fields_descriptions'] = json_encode($fields_descriptions); + $values['fields_values'] = io_json_mb_encode($fields_values); + $values['fields_descriptions'] = io_json_mb_encode($fields_descriptions); $values['name'] = $name; $values['command'] = $command; diff --git a/pandora_console/include/functions_io.php b/pandora_console/include/functions_io.php index ad4c0995bb..0b19a79547 100755 --- a/pandora_console/include/functions_io.php +++ b/pandora_console/include/functions_io.php @@ -415,4 +415,18 @@ function __ ($string /*, variable arguments */) { return vsprintf ($l10n->translate ($string), $args); } +/* + * json_encode for multibyte characters. + * + * @param string Text string to be encoded. +*/ +function io_json_mb_encode($string){ + $v = json_encode($string); + $v = preg_replace_callback("/\\\\u([0-9a-zA-Z]{4})/", + create_function('$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UTF-16");' + ), $v); + $v = preg_replace('/\\\\\//', '/', $v); + return $v; +} + ?>