- use proper unicode cleanup for JSON, fixes #1486356

release-0.6
alecpl 15 years ago
parent f47e2dc5ea
commit 2717f9f68e

@ -239,7 +239,7 @@ class rcube_json_output
if (!empty($this->callbacks)) if (!empty($this->callbacks))
$response['callbacks'] = $this->callbacks; $response['callbacks'] = $this->callbacks;
echo json_encode($response); echo json_serialize($response);
} }
@ -251,11 +251,11 @@ class rcube_json_output
private function get_js_commands() private function get_js_commands()
{ {
$out = ''; $out = '';
foreach ($this->commands as $i => $args) { foreach ($this->commands as $i => $args) {
$method = array_shift($args); $method = array_shift($args);
foreach ($args as $i => $arg) { foreach ($args as $i => $arg) {
$args[$i] = json_encode($arg); $args[$i] = json_serialize($arg);
} }
$out .= sprintf( $out .= sprintf(

@ -510,7 +510,7 @@ function rc_utf8_clean($input)
if (!is_string($input) || $input == '') if (!is_string($input) || $input == '')
return $input; return $input;
// iconv/mbstring are much faster (especially with long strings) // iconv/mbstring are much faster (especially with long strings)
if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF8', 'UTF8'))) if (function_exists('mb_convert_encoding') && ($res = mb_convert_encoding($input, 'UTF8', 'UTF8')))
return $res; return $res;
@ -563,6 +563,21 @@ function rc_utf8_clean($input)
return $out; 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 * Explode quoted string
* *

@ -414,12 +414,12 @@ class rcube_template extends rcube_html_page
{ {
$out = ''; $out = '';
if (!$this->framed && !empty($this->js_env)) { 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) { foreach ($this->js_commands as $i => $args) {
$method = array_shift($args); $method = array_shift($args);
foreach ($args as $i => $arg) { foreach ($args as $i => $arg) {
$args[$i] = json_encode($arg); $args[$i] = json_serialize($arg);
} }
$parent = $this->framed || preg_match('/^parent\./', $method); $parent = $this->framed || preg_match('/^parent\./', $method);
$out .= sprintf( $out .= sprintf(

@ -505,7 +505,7 @@ function rcmail_compose_body($attrib)
JQ(Q(rcube_label('close'))), JQ(Q(rcube_label('close'))),
JQ(Q(rcube_label('revertto'))), JQ(Q(rcube_label('revertto'))),
JQ(Q(rcube_label('nospellerrors'))), JQ(Q(rcube_label('nospellerrors'))),
json_encode($spellcheck_langs), json_serialize($spellcheck_langs),
$lang, $lang,
$attrib['id'], $attrib['id'],
JS_OBJECT_NAME), 'foot'); JS_OBJECT_NAME), 'foot');

@ -458,9 +458,6 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE, $replace=TRUE)
if ($header->flagged) if ($header->flagged)
$a_msg_flags['flagged'] = 1; $a_msg_flags['flagged'] = 1;
if ($browser->ie)
$a_msg_cols = rc_utf8_clean($a_msg_cols);
$OUTPUT->command('add_message_row', $OUTPUT->command('add_message_row',
$header->uid, $header->uid,
$a_msg_cols, $a_msg_cols,
@ -522,7 +519,7 @@ function rcmail_quota_display($attrib)
if (is_array($quota)) { if (is_array($quota)) {
$OUTPUT->add_script('$(document).ready(function(){ $OUTPUT->add_script('$(document).ready(function(){
rcmail.set_quota('.json_encode($quota).')});', 'foot'); rcmail.set_quota('.json_serialize($quota).')});', 'foot');
$quota = ''; $quota = '';
} }

@ -24,11 +24,6 @@ if ($uid = get_input_value('_uid', RCUBE_INPUT_POST))
if ($source) if ($source)
{ {
$browser = new rcube_browser;
if ($browser->ie)
$source = rc_utf8_clean($source);
$source = htmlspecialchars(trim($source)); $source = htmlspecialchars(trim($source));
$source = preg_replace('/\t/', '    ', $source); $source = preg_replace('/\t/', '    ', $source);
$source = preg_replace('/^([a-z0-9_:-]+)/im', '<font class="bold">'.'\1'.'</font>', $source); $source = preg_replace('/^([a-z0-9_:-]+)/im', '<font class="bold">'.'\1'.'</font>', $source);

Loading…
Cancel
Save