Fixed bug 8591: AJAX encoding is UTF-8, thus has problems with backend charsets ...
authorBenni Mack <benni.mack@typo3.org>
Tue, 10 Jun 2008 15:07:07 +0000 (15:07 +0000)
committerBenni Mack <benni.mack@typo3.org>
Tue, 10 Jun 2008 15:07:07 +0000 (15:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3790 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/classes/class.typo3ajax.php

index 0862cb3..46da493 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-06-10  Benjamin Mack  <benni@typo3.org>
+
+       * Fixed bug 8591: AJAX encoding is UTF-8, thus has problems with backend charsets (Thanks to Tobias Liebig)
+
 2008-06-10  Jeff Segars  <jeff@webempoweredchurch.org>
 
        * Followup to bugfix #8108: Extension configuration options are not always shown (Thanks to Steffen Kamper)
index 632b568..3e7cd4b 100644 (file)
@@ -40,18 +40,36 @@ class TYPO3AJAX {
        protected $content       = array();
        protected $contentFormat = 'plain';
        protected $charset       = 'utf-8';
+       protected $requestCharset = 'utf-8';
 
        /**
         * sets the charset and the ID for the AJAX call
+        * due some charset limitations in Javascript (prototype uses encodeURIcomponent, which converts
+        * all data to utf-8), we need to detect if the encoding of the request differs from the
+        * backend encoding (e.g. forceCharset), and then convert all incoming data (_GET and _POST)
+        * in the expected backend encoding.
         *
         * @param       string          the AJAX id
         * @return      void
         */
        public function __construct($ajaxId) {
-               global $LANG;
 
-               if($LANG->charSet != $this->charset) {
-                       $this->charset = $LANG->charSet;
+               if ($GLOBALS['LANG']->charSet != $this->charset) {
+                       $this->charset = $GLOBALS['LANG']->charSet;
+               }
+
+                       // get charset from current AJAX request (which is expected to be utf-8)
+               preg_match('/;\s*charset\s*=\s*([a-zA-Z0-9_-]*)/i', $_SERVER['CONTENT_TYPE'], $contenttype);
+               $charset = $GLOBALS['LANG']->csConvObj->parse_charset($contenttype[1]);
+               if ($charset && $charset != $this->requestCharset) {
+                       $this->requestCharset = $charset;
+               }
+
+                               // if the AJAX request does not have the same encoding like the backend
+                               // we need to convert the POST and GET parameters in the right charset
+               if ($this->charset != $this->requestCharset) {
+                       $GLOBALS['LANG']->csConvObj->convArray($_POST, $this->requestCharset, $this->charset);
+                       $GLOBALS['LANG']->csConvObj->convArray($_GET,  $this->requestCharset, $this->charset);
                }
 
                $this->ajaxId = $ajaxId;