Skip to content

Commit

Permalink
Fixed null deprecation in UnserializeArray.php (#4394)
Browse files Browse the repository at this point in the history
* Fixed issue #4352 null deprecation in UnserializeArray.php

* Added @ to suppress warnings and notices

* Suppress PHPMD ErrorControlOperator

* Fix suppress PHPMD ErrorControlOperator

* Update app/code/core/Mage/Core/Helper/UnserializeArray.php

phpstan fix

* Update app/code/core/Mage/Core/Helper/UnserializeArray.php

Co-authored-by: Sven Reichel <github-sr@hotmail.com>

* updated test result

* sonar-1

---------

Co-authored-by: Sven Reichel <github-sr@hotmail.com>
  • Loading branch information
kiatng and sreichel authored Feb 2, 2025
1 parent e5feff0 commit 31322c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/code/core/Mage/Core/Helper/UnserializeArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class Mage_Core_Helper_UnserializeArray
* @param string $str
* @return array
* @throws Exception
* @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
public function unserialize($str)
{
try {
$result = unserialize($str, ['allowed_classes' => false]);
$str = is_null($str) ? '' : $str;
$result = @unserialize($str, ['allowed_classes' => false]);
if ($result === false && $str !== serialize(false)) {
throw new Exception('Error unserializing data.');
}
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/Mage/Core/Helper/UnserializeArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ public function testUnserialize($expectedTesult, $string): void

public function provideUnserialize(): Generator
{
$errorMessage = 'Error unserializing data.';

yield 'null' => [
'Error unserializing data.',
$errorMessage,
null,
];
yield 'empty string' => [
'Error unserializing data.',
$errorMessage,
'',
];
yield 'random string' => [
'unserialize(): Error at offset 0 of 3 bytes',
$errorMessage,
'abc',
];
yield 'valid' => [
Expand Down

0 comments on commit 31322c4

Please sign in to comment.