diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-06-02 14:33:11 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-06-02 14:46:36 +0200 |
commit | 72c8504b99fbd423651bab0180a044c489ca05cc (patch) | |
tree | d7903d6e17aacbee1637642a0530bb8ea9e7a6ee /program/lib/Roundcube/rcube_db.php | |
parent | 6213c6a6e18848d861f2add83bdb69a1de3f5956 (diff) |
Fix bug where serialized strings were truncated in PDO::quote() (#1489142)
Conflicts:
CHANGELOG
program/lib/Roundcube/rcube_cache_shared.php
Diffstat (limited to 'program/lib/Roundcube/rcube_db.php')
-rw-r--r-- | program/lib/Roundcube/rcube_db.php | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php index 2f0a32ad6..adfe3ca3c 100644 --- a/program/lib/Roundcube/rcube_db.php +++ b/program/lib/Roundcube/rcube_db.php @@ -789,12 +789,19 @@ class rcube_db /** * Encodes non-UTF-8 characters in string/array/object (recursive) * - * @param mixed $input Data to fix + * @param mixed $input Data to fix + * @param bool $serialized Enable serialization * * @return mixed Properly UTF-8 encoded data */ - public static function encode($input) + public static function encode($input, $serialized = false) { + // use Base64 encoding to workaround issues with invalid + // or null characters in serialized string (#1489142) + if ($serialized) { + return base64_encode(serialize($input)); + } + if (is_object($input)) { foreach (get_object_vars($input) as $idx => $value) { $input->$idx = self::encode($value); @@ -805,6 +812,7 @@ class rcube_db foreach ($input as $idx => $value) { $input[$idx] = self::encode($value); } + return $input; } @@ -814,12 +822,19 @@ class rcube_db /** * Decodes encoded UTF-8 string/object/array (recursive) * - * @param mixed $input Input data + * @param mixed $input Input data + * @param bool $serialized Enable serialization * * @return mixed Decoded data */ - public static function decode($input) + public static function decode($input, $serialized = false) { + if ($serialized) { + // use Base64 encoding to workaround issues with invalid + // or null characters in serialized string (#1489142) + return @unserialize(base64_decode($input)); + } + if (is_object($input)) { foreach (get_object_vars($input) as $idx => $value) { $input->$idx = self::decode($value); |