diff --git a/msgpack.c b/msgpack.c index 3360b31..1876ec3 100644 --- a/msgpack.c +++ b/msgpack.c @@ -45,6 +45,9 @@ STD_PHP_INI_BOOLEAN( STD_PHP_INI_BOOLEAN( "msgpack.illegal_key_insert", "0", PHP_INI_ALL, OnUpdateBool, illegal_key_insert, zend_msgpack_globals, msgpack_globals) +STD_PHP_INI_BOOLEAN( + "msgpack.use_str8_serialization", "1", PHP_INI_ALL, OnUpdateBool, + use_str8_serialization, zend_msgpack_globals, msgpack_globals) PHP_INI_END() #if HAVE_PHP_SESSION @@ -77,6 +80,7 @@ static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) msgpack_globals->illegal_key_insert = 0; msgpack_globals->serialize.var_hash = NULL; msgpack_globals->serialize.level = 0; + msgpack_globals->use_str8_serialization = 1; } static ZEND_MINIT_FUNCTION(msgpack) diff --git a/msgpack/pack_template.h b/msgpack/pack_template.h index 37f4caf..6722df7 100644 --- a/msgpack/pack_template.h +++ b/msgpack/pack_template.h @@ -730,7 +730,7 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l) if(l < 32) { unsigned char d = 0xa0 | l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); - } else if (l < 256) { + } else if (l < 256 && MSGPACK_G(use_str8_serialization)) { unsigned char buf[2]; buf[0] = 0xd9; buf[1] = (uint8_t)l; msgpack_pack_append_buffer(x, buf, 2); diff --git a/php_msgpack.h b/php_msgpack.h index 492c448..ac9ddd9 100644 --- a/php_msgpack.h +++ b/php_msgpack.h @@ -24,6 +24,7 @@ ZEND_BEGIN_MODULE_GLOBALS(msgpack) zend_bool error_display; zend_bool php_only; zend_bool illegal_key_insert; + zend_bool use_str8_serialization; struct { void *var_hash; unsigned level; diff --git a/tests/029.phpt b/tests/029.phpt index 36efb39..d623ce9 100644 --- a/tests/029.phpt +++ b/tests/029.phpt @@ -8,7 +8,7 @@ if (!extension_loaded("session")) { } ?> --FILE-- - Local Value => Master Value msgpack.error_display => On => On msgpack.illegal_key_insert => Off => Off msgpack.php_only => On => On +msgpack.use_str8_serialization => On => On diff --git a/tests/137.phpt b/tests/137.phpt index 70671f0..ab9c2e8 100644 --- a/tests/137.phpt +++ b/tests/137.phpt @@ -7,21 +7,28 @@ unpack/pack str8 } --FILE-- --EXPECTF-- Simple test for short string - type str8 +string(84) "d92853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238" +OK +string(86) "da002853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238" OK