summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorDavid <david0@github.com>2014-07-10 17:44:40 +0200
committerDavid <david0@github.com>2014-07-10 18:40:38 +0200
commit8e07d0781150206fae722d9b9dcbdafd727665f6 (patch)
tree4ae8f3c88fb61d1da4e6c97b69f75647058f3d89 /framework
parent37a1d886c6960080bbd03cad757c722b494a0220 (diff)
Convert encoding of all values inside an array before json_serialize (Fixes #524)
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/Javascripts/TJavaScript.php25
1 files changed, 20 insertions, 5 deletions
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index 0f6fef1c..c50a3742 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -206,7 +206,6 @@ class TJavaScript
else
return '';
}
-
/**
* Encodes a PHP variable into javascript string.
* This method invokes json_encode to perform the encoding.
@@ -215,16 +214,32 @@ class TJavaScript
*/
public static function jsonEncode($value, $options = 0)
{
- if (is_string($value) &&
- ($g=Prado::getApplication()->getGlobalization(false))!==null &&
- strtoupper($enc=$g->getCharset())!='UTF-8')
- $value=iconv($enc, 'UTF-8', $value);
+ if (($g=Prado::getApplication()->getGlobalization(false))!==null &&
+ strtoupper($enc=$g->getCharset())!='UTF-8') {
+ self::convertToUtf8($value, $enc);
+ }
+
$s = @json_encode($value,$options);
self::checkJsonError();
return $s;
}
/**
+ * Encodes an string or the content of an array to UTF8
+ * @param string|array|mixed $value
+ * @param string $sourceEncoding
+ */
+ private static function convertToUtf8(&$value, $sourceEncoding) {
+ if(is_string($value))
+ $value=iconv($sourceEncoding, 'UTF-8', $value);
+ else if (is_array($value))
+ {
+ foreach($value as &$element)
+ self::convertToUtf8($element, $sourceEncoding);
+ }
+ }
+
+ /**
* Decodes a javascript string into PHP variable.
* This method invokes json_decode to perform the decoding.
* @param string string to be decoded