From a012002652d4b580eb6e74bf9ea173788ccad5b4 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 26 Jan 2009 11:09:14 +0000 Subject: [PATCH] Fixed bug #46419 (Elements of associative arrays with NULL value are lost) --- NEWS | 2 ++ ext/soap/php_encoding.c | 45 +++++++++++++++---------------- ext/soap/tests/bugs/bug46419.phpt | 43 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 ext/soap/tests/bugs/bug46419.phpt diff --git a/NEWS b/NEWS index 012158b8c7..fed548ec6e 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,8 @@ PHP NEWS - Fixed bug #46701 (Creating associative array with long values in the key fails on 32bit linux). (Shire) - Fixed bug #46699 (xml_parse crash when parser is namespace aware). (Rob) +- Fixed bug #46419 (Elements of associative arrays with NULL value are lost). + (Dmitry) - Fixed bug #46282 (Corrupt DBF When Using DATE). (arne at bukkie dot nl) - Fixed bug #46005 (User not consistently logged under Apache2). (admorten at umich dot edu, Stas) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 68c9d5858b..613a226629 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -2662,33 +2662,32 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP ulong int_val; zend_hash_get_current_data(data->value.ht, (void **)&temp_data); - if (Z_TYPE_PP(temp_data) != IS_NULL) { - item = xmlNewNode(NULL, BAD_CAST("item")); - xmlAddChild(xmlParam, item); - key = xmlNewNode(NULL, BAD_CAST("key")); - xmlAddChild(item,key); - if (zend_hash_get_current_key(data->value.ht, &key_val, &int_val, FALSE) == HASH_KEY_IS_STRING) { - if (style == SOAP_ENCODED) { - set_xsi_type(key, "xsd:string"); - } - xmlNodeSetContent(key, BAD_CAST(key_val)); - } else { - smart_str tmp = {0}; - smart_str_append_long(&tmp, int_val); - smart_str_0(&tmp); - - if (style == SOAP_ENCODED) { - set_xsi_type(key, "xsd:int"); - } - xmlNodeSetContentLen(key, BAD_CAST(tmp.c), tmp.len); - - smart_str_free(&tmp); + item = xmlNewNode(NULL, BAD_CAST("item")); + xmlAddChild(xmlParam, item); + key = xmlNewNode(NULL, BAD_CAST("key")); + xmlAddChild(item,key); + if (zend_hash_get_current_key(data->value.ht, &key_val, &int_val, FALSE) == HASH_KEY_IS_STRING) { + if (style == SOAP_ENCODED) { + set_xsi_type(key, "xsd:string"); } + xmlNodeSetContent(key, BAD_CAST(key_val)); + } else { + smart_str tmp = {0}; + smart_str_append_long(&tmp, int_val); + smart_str_0(&tmp); - xparam = master_to_xml(get_conversion((*temp_data)->type), (*temp_data), style, item); + if (style == SOAP_ENCODED) { + set_xsi_type(key, "xsd:int"); + } + xmlNodeSetContentLen(key, BAD_CAST(tmp.c), tmp.len); - xmlNodeSetName(xparam, BAD_CAST("value")); + smart_str_free(&tmp); } + + xparam = master_to_xml(get_conversion((*temp_data)->type), (*temp_data), style, item); + + xmlNodeSetName(xparam, BAD_CAST("value")); + zend_hash_move_forward(data->value.ht); } } diff --git a/ext/soap/tests/bugs/bug46419.phpt b/ext/soap/tests/bugs/bug46419.phpt new file mode 100644 index 0000000000..cb113e28d2 --- /dev/null +++ b/ext/soap/tests/bugs/bug46419.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #46419 (Elements of associative arrays with NULL value are lost) +--SKIPIF-- + +--FILE-- + 1, 'b' => NULL, 'c' => 2, 'd'=>''); +} + +class LocalSoapClient extends SoapClient { + + function __construct($wsdl, $options) { + parent::__construct($wsdl, $options); + $this->server = new SoapServer($wsdl, $options); + $this->server->addFunction('bar'); + } + + function __doRequest($request, $location, $action, $version, $one_way = 0) { + ob_start(); + $this->server->handle($request); + $response = ob_get_contents(); + ob_end_clean(); + return $response; + } + +} + +$x = new LocalSoapClient(NULL,array('location'=>'test://', + 'uri'=>'http://testuri.org')); +var_dump($x->bar()); +?> +--EXPECT-- +array(4) { + ["a"]=> + int(1) + ["b"]=> + NULL + ["c"]=> + int(2) + ["d"]=> + string(0) "" +} -- 2.50.1