Fix Request #67453 Allow to unserialize empty data.

SplDoublyLinkedList, SplObjectStorage and ArrayObject have empty
constructor (no arg), so it make sense to allow to unserialize empty
data.

This allow the hack (used in various place, including PHPUnit) to
instanciate class without call to constructor to work.
This commit is contained in:
Remi Collet 2014-06-17 09:38:54 +02:00
parent b538816b0b
commit ea466a316f
5 changed files with 6 additions and 12 deletions

View file

@ -1749,7 +1749,6 @@ SPL_METHOD(Array, unserialize)
} }
if (buf_len == 0) { if (buf_len == 0) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Empty serialized string cannot be empty");
return; return;
} }

View file

@ -1192,7 +1192,6 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
} }
if (buf_len == 0) { if (buf_len == 0) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Serialized string cannot be empty");
return; return;
} }

View file

@ -831,7 +831,6 @@ SPL_METHOD(SplObjectStorage, unserialize)
} }
if (buf_len == 0) { if (buf_len == 0) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Empty serialized string cannot be empty");
return; return;
} }

View file

@ -1,5 +1,5 @@
--TEST-- --TEST--
ArrayObject: test that you cannot unserialize a empty string ArrayObject: test that you can unserialize a empty string
--CREDITS-- --CREDITS--
Havard Eide <nucleuz@gmail.com> Havard Eide <nucleuz@gmail.com>
#PHPTestFest2009 Norway 2009-06-09 \o/ #PHPTestFest2009 Norway 2009-06-09 \o/
@ -8,9 +8,6 @@ Havard Eide <nucleuz@gmail.com>
$a = new ArrayObject(array()); $a = new ArrayObject(array());
$a->unserialize(""); $a->unserialize("");
?> ?>
Done
--EXPECTF-- --EXPECTF--
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Empty serialized string cannot be empty' in %s.php:%d Done
Stack trace:
#0 %s(%d): ArrayObject->unserialize('')
#1 {main}
thrown in %s.php on line %d

View file

@ -1,5 +1,5 @@
--TEST-- --TEST--
Check that SplObjectStorage::unserialize throws exception when NULL passed Check that SplObjectStorage::unserialize doesn't throws exception when NULL passed
--CREDITS-- --CREDITS--
PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com)
--FILE-- --FILE--
@ -14,6 +14,6 @@ try {
} }
?> ?>
Done
--EXPECTF-- --EXPECTF--
Empty serialized string cannot be empty Done