From 2717f9f68e74277379c065d32bd0771976e49c86 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Fri, 11 Dec 2009 11:53:54 -0500 Subject: [PATCH] - use proper unicode cleanup for JSON, fixes #1486356 --- program/include/rcube_shared.inc | 17 ++++++++++++++++- program/steps/mail/compose.inc | 2 +- program/include/rcube_json_output.php | 6 +++--- program/steps/mail/func.inc | 5 +---- program/include/rcube_template.php | 4 ++-- program/steps/mail/headers.inc | 5 ----- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/program/include/rcube_json_output.php b/program/include/rcube_json_output.php index cb8a7db..080bab6 100644 --- a/program/include/rcube_json_output.php +++ b/program/include/rcube_json_output.php @@ -239,7 +239,7 @@ if (!empty($this->callbacks)) $response['callbacks'] = $this->callbacks; - echo json_encode($response); + echo json_serialize($response); } @@ -251,11 +251,11 @@ private function get_js_commands() { $out = ''; - + foreach ($this->commands as $i => $args) { $method = array_shift($args); foreach ($args as $i => $arg) { - $args[$i] = json_encode($arg); + $args[$i] = json_serialize($arg); } $out .= sprintf( diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc index f4c6f71..547174b 100644 --- a/program/include/rcube_shared.inc +++ b/program/include/rcube_shared.inc @@ -510,7 +510,7 @@ if (!is_string($input) || $input == '') return $input; - + // iconv/mbstring are much faster (especially with long strings) if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF8', 'UTF8'))) return $res; @@ -563,6 +563,21 @@ return $out; } + +/** + * Convert a variable into a javascript object notation + * + * @param mixed Input value + * @return string Serialized JSON string + */ +function json_serialize($input) +{ + $input = rc_utf8_clean($input); + + return json_encode($input); +} + + /** * Explode quoted string * diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php index 19f2d43..5226f8d 100755 --- a/program/include/rcube_template.php +++ b/program/include/rcube_template.php @@ -414,12 +414,12 @@ { $out = ''; if (!$this->framed && !empty($this->js_env)) { - $out .= JS_OBJECT_NAME . '.set_env('.json_encode($this->js_env).");\n"; + $out .= JS_OBJECT_NAME . '.set_env('.json_serialize($this->js_env).");\n"; } foreach ($this->js_commands as $i => $args) { $method = array_shift($args); foreach ($args as $i => $arg) { - $args[$i] = json_encode($arg); + $args[$i] = json_serialize($arg); } $parent = $this->framed || preg_match('/^parent\./', $method); $out .= sprintf( diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 842f28c..560142b 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -505,7 +505,7 @@ JQ(Q(rcube_label('close'))), JQ(Q(rcube_label('revertto'))), JQ(Q(rcube_label('nospellerrors'))), - json_encode($spellcheck_langs), + json_serialize($spellcheck_langs), $lang, $attrib['id'], JS_OBJECT_NAME), 'foot'); diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 94f455a..b874817 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -458,9 +458,6 @@ if ($header->flagged) $a_msg_flags['flagged'] = 1; - if ($browser->ie) - $a_msg_cols = rc_utf8_clean($a_msg_cols); - $OUTPUT->command('add_message_row', $header->uid, $a_msg_cols, @@ -522,7 +519,7 @@ if (is_array($quota)) { $OUTPUT->add_script('$(document).ready(function(){ - rcmail.set_quota('.json_encode($quota).')});', 'foot'); + rcmail.set_quota('.json_serialize($quota).')});', 'foot'); $quota = ''; } diff --git a/program/steps/mail/headers.inc b/program/steps/mail/headers.inc index 4e3f969..653fb96 100644 --- a/program/steps/mail/headers.inc +++ b/program/steps/mail/headers.inc @@ -24,11 +24,6 @@ if ($source) { - $browser = new rcube_browser; - - if ($browser->ie) - $source = rc_utf8_clean($source); - $source = htmlspecialchars(trim($source)); $source = preg_replace('/\t/', ' ', $source); $source = preg_replace('/^([a-z0-9_:-]+)/im', '<font class="bold">'.'\1'.'</font>', $source); -- Gitblit v1.9.1