# HG changeset patch
# User Dan
# Date 1237697049 14400
# Node ID 218b6d4de908924b0c788f7aea9625cf65dac8b5
# Parent 9788f2b7e08a754844703f9a17f898b3e5065331
JSON: Properly handles unicode escape sequences (\u####) now
diff -r 9788f2b7e08a -r 218b6d4de908 ajax.php
--- a/ajax.php Sat Mar 21 19:11:30 2009 -0400
+++ b/ajax.php Sun Mar 22 00:44:09 2009 -0400
@@ -187,9 +187,16 @@
if ( !isset($_POST['r']) )
die('Invalid request');
- $request = enano_json_decode($_POST['r']);
- if ( !isset($request['src']) || !isset($request['summary']) || !isset($request['minor_edit']) || !isset($request['time']) || !isset($request['draft']) )
- die('Invalid request');
+ try
+ {
+ $request = enano_json_decode($_POST['r']);
+ if ( !isset($request['src']) || !isset($request['summary']) || !isset($request['minor_edit']) || !isset($request['time']) || !isset($request['draft']) )
+ die('Invalid request');
+ }
+ catch(Zend_Json_Exception $e)
+ {
+ die("JSON parsing failed. View as HTML to see full report.\n
\n
" . htmlspecialchars(strval($e)) . "
" . htmlspecialchars($_POST['r']) . ""); + } $time = intval($request['time']); diff -r 9788f2b7e08a -r 218b6d4de908 includes/clientside/static/editor.js --- a/includes/clientside/static/editor.js Sat Mar 21 19:11:30 2009 -0400 +++ b/includes/clientside/static/editor.js Sun Mar 22 00:44:09 2009 -0400 @@ -13,7 +13,7 @@ return true; if ( editor_open ) return true; - load_component(['l10n', 'template-compiler', 'messagebox', 'fadefilter', 'flyin']); + load_component(['l10n', 'template-compiler', 'messagebox', 'fadefilter', 'flyin', 'toolbar']); selectButtonMinor('edit'); selectButtonMajor('article'); setAjaxLoading(); diff -r 9788f2b7e08a -r 218b6d4de908 includes/json2.php --- a/includes/json2.php Sat Mar 21 19:11:30 2009 -0400 +++ b/includes/json2.php Sun Mar 22 00:44:09 2009 -0400 @@ -773,6 +773,9 @@ case '\'' : $result .= '\''; break; + case 'u': + $result .= self::decode_unicode_byte(substr($str, $i + 1, 4)); + break; default: throw new Zend_Json_Exception("Illegal escape " . "sequence '" . $chr . "'"); @@ -904,6 +907,41 @@ return($this->_token); } + + /** + * Handle a Unicode byte; local to Enano. + * @param string 4 character byte sequence + * @return string + */ + + protected function decode_unicode_byte($byte) + { + if ( strlen($byte) != 4 ) + throw new Zend_Json_Exception("Invalid Unicode sequence \\u$byte"); + + $value = hexdec($byte); + + if ($value < 0x0080) + { + // 1 byte: 0xxxxxxx + $character = chr($value); + } + else if ($value < 0x0800) + { + // 2 bytes: 110xxxxx 10xxxxxx + $character = + chr((($value & 0x07c0) >> 6) | 0xc0) + . chr(($value & 0x3f) | 0x80); + } + else + { + // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx + $character = + chr((($value & 0xf000) >> 12) | 0xe0) + . chr((($value & 0x0fc0) >> 6) | 0x80) + . chr(($value & 0x3f) | 0x80); + } + } } /**