Skip to content

Commit

Permalink
Fixed issue #23 (Empty objects get serialized with incorrect type)
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Nov 19, 2013
1 parent 629676d commit 1a9d248
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
51 changes: 22 additions & 29 deletions msgpack_pack.c
Expand Up @@ -276,35 +276,28 @@ inline static void msgpack_serialize_array(

if (object)
{
if (n == 0)
{
msgpack_pack_map(buf, n);
}
else
{
if (MSGPACK_G(php_only))
{
if (Z_ISREF_P(val))
{
msgpack_pack_map(buf, n + 2);
msgpack_pack_nil(buf);
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
}
else
{
msgpack_pack_map(buf, n + 1);
}

msgpack_pack_nil(buf);

msgpack_serialize_string(buf, class_name, name_len);
}
else
{
msgpack_pack_array(buf, n);
hash = 0;
}
}
if (MSGPACK_G(php_only))
{
if (Z_ISREF_P(val))
{
msgpack_pack_map(buf, n + 2);
msgpack_pack_nil(buf);
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
}
else
{
msgpack_pack_map(buf, n + 1);
}

msgpack_pack_nil(buf);

msgpack_serialize_string(buf, class_name, name_len);
}
else
{
msgpack_pack_array(buf, n);
hash = 0;
}
}
else if (n == 0)
{
Expand Down
16 changes: 16 additions & 0 deletions tests/issue023.phpt
@@ -0,0 +1,16 @@
--TEST--
Issue #23 (Empty objects get serialized with incorrect type)
--SKIPIF--
<?php
if (!extension_loaded("msgpack")) {
echo "skip";
}
--FILE--
<?php
class test {}
print_r(msgpack_unserialize (msgpack_serialize (new test())));
?>
--EXPECTF--
test Object
(
)

0 comments on commit 1a9d248

Please sign in to comment.