Fixed bug #11361: Backend TYPO3 AJAX-Interface: json encoded result empty if it conta...
authorJeff Segars <jsegars@alumni.rice.edu>
Wed, 16 Sep 2009 14:52:48 +0000 (14:52 +0000)
committerJeff Segars <jsegars@alumni.rice.edu>
Wed, 16 Sep 2009 14:52:48 +0000 (14:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5946 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/classes/class.typo3ajax.php

index 2059af2..a2dd627 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2009-09-16  Jeff Segars  <jeff@webempoweredchurch.org>
 
        * Added feature #11819: Added inline Javascript rendering type for TYPO3AJAX
+       * Fixed bug #11361: Backend TYPO3 AJAX-Interface: json encoded result empty if it contains non-utf-8 characters (thanks to Benjamin Mack)
 
 2009-09-16  Rupert Germann  <rupi@gmx.li>
 
index 1414567..d0cfc83 100644 (file)
@@ -252,9 +252,15 @@ class TYPO3AJAX {
         * @return      void
         */
        protected function renderAsJSON() {
+                       // if the backend does not run in UTF-8 then we need to convert it to unicode as
+                       // the json_encode method will return empty otherwise
+               if ($this->charset != $this->requestCharset) {
+                       $GLOBALS['LANG']->csConvObj->convArray($this->content, $this->charset, $this->requestCharset);
+               }
+
                $content = json_encode($this->content);
 
-               header('Content-type: application/json; charset='.$this->charset);
+               header('Content-type: application/json; charset='.$this->requestCharset);
                header('X-JSON: '.($this->contentFormat != 'jsonbody' ? $content : true));
 
                        // bring content in xhr.responseText except when in "json head only" mode
@@ -270,6 +276,12 @@ class TYPO3AJAX {
         * @return       void
         */
        protected function renderAsJavascript() {
+                       // if the backend does not run in UTF-8 then we need to convert it to unicode as
+                       // the json_encode method will return empty otherwise
+               if ($this->charset != $this->requestCharset) {
+                       $GLOBALS['LANG']->csConvObj->convArray($this->content, $this->charset, $this->requestCharset);
+               }
+
                $content = '<script type="text/javascript">
                                        /*<![CDATA[*/
 
@@ -278,7 +290,7 @@ class TYPO3AJAX {
                                        /*]]>*/
                                        </script>';
 
-               header('Content-type: text/html; charset=' . $this->charset);
+               header('Content-type: text/html; charset=' . $this->requestCharset);
                echo $content;
        }
 }