diff options
author | robocoder <anthon.pang@gmail.com> | 2009-12-12 01:33:11 +0300 |
---|---|---|
committer | robocoder <anthon.pang@gmail.com> | 2009-12-12 01:33:11 +0300 |
commit | 9eddb33e69fcee2aea7f61247b434fafc36afc1a (patch) | |
tree | 6333115d668fa3f6166377f9263a89b6821adcc0 /core/Cookie.php | |
parent | b1cba885cd6c88d8f55d77726413604d528c0de9 (diff) |
refactor [1637] and add unit test
git-svn-id: http://dev.piwik.org/svn/trunk@1667 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/Cookie.php')
-rw-r--r-- | core/Cookie.php | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/core/Cookie.php b/core/Cookie.php index 6abbd65bad..4868d5d1f5 100644 --- a/core/Cookie.php +++ b/core/Cookie.php @@ -162,18 +162,9 @@ class Piwik_Cookie if(!is_numeric($varValue)) { $varValue = base64_decode($varValue); - // some of the values may be serialized array so we try to unserialize it - if (preg_match('/^a:[0-9]+:\{/', $varValue) - && !preg_match('/(^|;|{|})O:[0-9]+:"/', $varValue) - && strpos($varValue, "\0") === false) - { - // we set the unserialized version only for arrays as you can have set a serialized string on purpose - if( ($arrayValue = @unserialize($varValue)) !== false - && is_array($arrayValue) ) - { - $varValue = $arrayValue; - } - } + + // some of the values may be serialized array so we try to unserialize it + $varValue = self::unserialize_array($varValue); } $this->set($varName, $varValue); @@ -267,4 +258,28 @@ class Piwik_Cookie { return Piwik_Common::sanitizeInputValues($value); } + + /** + * Unserialize (serialized) array + * + * @param string + * @return array or original string if not unserializable + */ + public static function unserialize_array( $str ) + { + // we set the unserialized version only for arrays as you can have set a serialized string on purpose + if (preg_match('/^a:[0-9]+:{/', $str) + && !preg_match('/(^|;|{|})O:[0-9]+:"/', $str) + && strpos($str, "\0") === false) + { + if( ($arrayValue = @unserialize($str)) !== false + && is_array($arrayValue) ) + { + return $arrayValue; + } + } + + // return original string + return $str; + } } |