From ceded0dd46bb13950b2162c4ea6a93a81787e843 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 24 Sep 2024 16:16:22 +0100 Subject: [PATCH] Removed old, almost unused and undocumented lib/Unserialize --- app/code/core/Mage/Core/Helper/String.php | 17 +-- app/code/core/Mage/Sales/Model/Quote/Item.php | 2 +- lib/Unserialize/Parser.php | 48 -------- lib/Unserialize/Reader/Arr.php | 111 ------------------ lib/Unserialize/Reader/ArrKey.php | 70 ----------- lib/Unserialize/Reader/ArrValue.php | 89 -------------- lib/Unserialize/Reader/Bool.php | 52 -------- lib/Unserialize/Reader/Dbl.php | 52 -------- lib/Unserialize/Reader/Int.php | 52 -------- lib/Unserialize/Reader/Null.php | 50 -------- lib/Unserialize/Reader/Str.php | 82 ------------- 11 files changed, 4 insertions(+), 621 deletions(-) delete mode 100644 lib/Unserialize/Parser.php delete mode 100644 lib/Unserialize/Reader/Arr.php delete mode 100644 lib/Unserialize/Reader/ArrKey.php delete mode 100644 lib/Unserialize/Reader/ArrValue.php delete mode 100644 lib/Unserialize/Reader/Bool.php delete mode 100644 lib/Unserialize/Reader/Dbl.php delete mode 100644 lib/Unserialize/Reader/Int.php delete mode 100644 lib/Unserialize/Reader/Null.php delete mode 100644 lib/Unserialize/Reader/Str.php diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index 1d3a18bd3..73a5e09f8 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -512,23 +512,14 @@ public function uniOrd($c) * UnSerialize string * @param string $str * @return mixed|null - * @throws Exception */ public function unserialize($str) { if (is_null($str)) { return null; } - $reader = new Unserialize_Reader_ArrValue('data'); - $prevChar = null; - for ($i = 0; $i < strlen($str); $i++) { - $char = $str[$i]; - $result = $reader->read($char, $prevChar); - if (!is_null($result)) { - return $result; - } - $prevChar = $char; - } + + return unserialize($str); } /** @@ -553,9 +544,7 @@ public function isSerializedArrayOrObject($data) public function validateSerializedObject($str) { if ($this->isSerializedArrayOrObject($str)) { - try { - $this->unserialize($str); - } catch (Exception $e) { + if (!unserialize($str)) { return false; } } diff --git a/app/code/core/Mage/Sales/Model/Quote/Item.php b/app/code/core/Mage/Sales/Model/Quote/Item.php index 6e0f6ba54..d120fc3c3 100644 --- a/app/code/core/Mage/Sales/Model/Quote/Item.php +++ b/app/code/core/Mage/Sales/Model/Quote/Item.php @@ -516,7 +516,7 @@ public function compare($item) // dispose of some options params, that can cramp comparing of arrays if (is_string($itemOptionValue) && is_string($optionValue)) { try { - /** @var Unserialize_Parser $parser */ + /** @var Mage_Core_Helper_UnserializeArray $parser */ $parser = Mage::helper('core/unserializeArray'); $_itemOptionValue = diff --git a/lib/Unserialize/Parser.php b/lib/Unserialize/Parser.php deleted file mode 100644 index af508118a..000000000 --- a/lib/Unserialize/Parser.php +++ /dev/null @@ -1,48 +0,0 @@ -read($char, $prevChar); - if (!is_null($arr)) { - return $arr; - } - $prevChar = $char; - } - throw new Exception('Error during unserialization'); - } -} diff --git a/lib/Unserialize/Reader/Arr.php b/lib/Unserialize/Reader/Arr.php deleted file mode 100644 index abb2d366d..000000000 --- a/lib/Unserialize/Reader/Arr.php +++ /dev/null @@ -1,111 +0,0 @@ -_result = !is_null($this->_result) ? $this->_result : []; - - if (is_null($this->_status) && $prevChar == Unserialize_Parser::SYMBOL_COLON) { - $this->_length .= $char; - $this->_status = self::READING_LENGTH; - return null; - } - - if ($this->_status == self::READING_LENGTH) { - if ($char == Unserialize_Parser::SYMBOL_COLON) { - $this->_length = (int)$this->_length; - if ($this->_length == 0) { - $this->_status = self::FINISHED_ARR; - return null; - } - $this->_status = self::FINISHED_LENGTH; - } else { - $this->_length .= $char; - } - } - - if ($this->_status == self::FINISHED_LENGTH && $prevChar == '{') { - $this->_reader = new Unserialize_Reader_ArrKey(); - $this->_status = self::READING_KEY; - } - - if ($this->_status == self::READING_KEY) { - $key = $this->_reader->read($char, $prevChar); - if (!is_null($key)) { - $this->_status = self::READING_VALUE; - $this->_reader = new Unserialize_Reader_ArrValue($key); - return null; - } - } - - if ($this->_status == self::READING_VALUE) { - $value = $this->_reader->read($char, $prevChar); - if (!is_null($value)) { - $this->_result[$this->_reader->key] = - ($value == Unserialize_Reader_Null::NULL_VALUE && $prevChar == Unserialize_Parser::TYPE_NULL) - ? null - : $value; - if (count($this->_result) < $this->_length) { - $this->_reader = new Unserialize_Reader_ArrKey(); - $this->_status = self::READING_KEY; - return null; - } else { - $this->_status = self::FINISHED_ARR; - return null; - } - } - } - - if ($this->_status == self::FINISHED_ARR) { - if ($char == '}') { - return $this->_result; - } - } - } -} diff --git a/lib/Unserialize/Reader/ArrKey.php b/lib/Unserialize/Reader/ArrKey.php deleted file mode 100644 index 0f2b4c345..000000000 --- a/lib/Unserialize/Reader/ArrKey.php +++ /dev/null @@ -1,70 +0,0 @@ -_status = self::NOT_STARTED; - } - - /** - * @param string $char - * @param string $prevChar - * @return mixed|null - * @throws Exception - */ - public function read($char, $prevChar) - { - if ($this->_status == self::NOT_STARTED) { - switch ($char) { - case Unserialize_Parser::TYPE_STRING: - $this->_reader = new Unserialize_Reader_Str(); - $this->_status = self::READING_KEY; - break; - case Unserialize_Parser::TYPE_INT: - $this->_reader = new Unserialize_Reader_Int(); - $this->_status = self::READING_KEY; - break; - default: - throw new Exception('Unsupported data type ' . $char); - } - } - - if ($this->_status == self::READING_KEY) { - $key = $this->_reader->read($char, $prevChar); - if (!is_null($key)) { - return $key; - } - } - return null; - } -} diff --git a/lib/Unserialize/Reader/ArrValue.php b/lib/Unserialize/Reader/ArrValue.php deleted file mode 100644 index 7f70802d7..000000000 --- a/lib/Unserialize/Reader/ArrValue.php +++ /dev/null @@ -1,89 +0,0 @@ -_status = self::NOT_STARTED; - $this->key = $key; - } - - /** - * @param string $char - * @param string $prevChar - * @return mixed|null - * @throws Exception - */ - public function read($char, $prevChar) - { - if ($this->_status == self::NOT_STARTED) { - switch ($char) { - case Unserialize_Parser::TYPE_STRING: - $this->_reader = new Unserialize_Reader_Str(); - $this->_status = self::READING_VALUE; - break; - case Unserialize_Parser::TYPE_ARRAY: - $this->_reader = new Unserialize_Reader_Arr(); - $this->_status = self::READING_VALUE; - break; - case Unserialize_Parser::TYPE_INT: - $this->_reader = new Unserialize_Reader_Int(); - $this->_status = self::READING_VALUE; - break; - case Unserialize_Parser::TYPE_BOOL: - $this->_reader = new Unserialize_Reader_Bool(); - $this->_status = self::READING_VALUE; - break; - case Unserialize_Parser::TYPE_DOUBLE: - $this->_reader = new Unserialize_Reader_Dbl(); - $this->_status = self::READING_VALUE; - break; - case Unserialize_Parser::TYPE_NULL: - $this->_reader = new Unserialize_Reader_Null(); - $this->_status = self::READING_VALUE; - break; - default: - throw new Exception('Unsupported data type ' . $char); - } - } - - if ($this->_status == self::READING_VALUE) { - $value = $this->_reader->read($char, $prevChar); - if (!is_null($value)) { - return $value; - } - } - return null; - } -} diff --git a/lib/Unserialize/Reader/Bool.php b/lib/Unserialize/Reader/Bool.php deleted file mode 100644 index a12cf7b54..000000000 --- a/lib/Unserialize/Reader/Bool.php +++ /dev/null @@ -1,52 +0,0 @@ -_value .= $char; - $this->_status = self::READING_VALUE; - return null; - } - - if ($this->_status == self::READING_VALUE) { - if ($char !== Unserialize_Parser::SYMBOL_SEMICOLON) { - $this->_value .= $char; - } else { - return (bool)$this->_value; - } - } - return null; - } -} diff --git a/lib/Unserialize/Reader/Dbl.php b/lib/Unserialize/Reader/Dbl.php deleted file mode 100644 index c98671e84..000000000 --- a/lib/Unserialize/Reader/Dbl.php +++ /dev/null @@ -1,52 +0,0 @@ -_value .= $char; - $this->_status = self::READING_VALUE; - return null; - } - - if ($this->_status == self::READING_VALUE) { - if ($char !== Unserialize_Parser::SYMBOL_SEMICOLON) { - $this->_value .= $char; - } else { - return (float)$this->_value; - } - } - return null; - } -} diff --git a/lib/Unserialize/Reader/Int.php b/lib/Unserialize/Reader/Int.php deleted file mode 100644 index 239e4f1f9..000000000 --- a/lib/Unserialize/Reader/Int.php +++ /dev/null @@ -1,52 +0,0 @@ -_value .= $char; - $this->_status = self::READING_VALUE; - return null; - } - - if ($this->_status == self::READING_VALUE) { - if ($char !== Unserialize_Parser::SYMBOL_SEMICOLON) { - $this->_value .= $char; - } else { - return (int)$this->_value; - } - } - return null; - } -} diff --git a/lib/Unserialize/Reader/Null.php b/lib/Unserialize/Reader/Null.php deleted file mode 100644 index a13e3c4ef..000000000 --- a/lib/Unserialize/Reader/Null.php +++ /dev/null @@ -1,50 +0,0 @@ -_value = self::NULL_VALUE; - $this->_status = self::READING_VALUE; - return null; - } - - if ($this->_status == self::READING_VALUE && $char == Unserialize_Parser::SYMBOL_SEMICOLON) { - return $this->_value; - } - return null; - } -} diff --git a/lib/Unserialize/Reader/Str.php b/lib/Unserialize/Reader/Str.php deleted file mode 100644 index f1a09df59..000000000 --- a/lib/Unserialize/Reader/Str.php +++ /dev/null @@ -1,82 +0,0 @@ -_status) && $prevChar == Unserialize_Parser::SYMBOL_COLON) { - $this->_status = self::READING_LENGTH; - } - - if ($this->_status == self::READING_LENGTH) { - if ($char != Unserialize_Parser::SYMBOL_COLON) { - $this->_length .= $char; - } else { - $this->_length = (int)$this->_length; - $this->_status = self::FINISHED_LENGTH; - } - } - - if ($this->_status == self::FINISHED_LENGTH) { - if ($char == Unserialize_Parser::SYMBOL_QUOTE) { - $this->_status = self::READING_VALUE; - return null; - } - } - - if ($this->_status == self::READING_VALUE) { - if (is_null($this->_value)) { - $this->_value = ''; - } - - if (strlen($this->_value) < $this->_length) { - $this->_value .= $char; - return null; - } - - if (strlen($this->_value) == $this->_length) { - if ($char == Unserialize_Parser::SYMBOL_SEMICOLON && $prevChar == Unserialize_Parser::SYMBOL_QUOTE) { - return (string)$this->_value; - } - } - } - return null; - } -}