felipe                                   Wed, 25 Nov 2009 02:03:02 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=291285

Log:
- Fixed bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)

Bug: http://bugs.php.net/50285 (Verified) xmlrpc does not preserve keys in 
encoded indexed arrays
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    A   php/php-src/branches/PHP_5_2/ext/xmlrpc/tests/bug50285.phpt
    U   php/php-src/branches/PHP_5_2/ext/xmlrpc/xmlrpc-epi-php.c
    U   php/php-src/branches/PHP_5_3/NEWS
    A   php/php-src/branches/PHP_5_3/ext/xmlrpc/tests/bug50285.phpt
    U   php/php-src/branches/PHP_5_3/ext/xmlrpc/xmlrpc-epi-php.c
    A   php/php-src/trunk/ext/xmlrpc/tests/bug50285.phpt
    U   php/php-src/trunk/ext/xmlrpc/xmlrpc-epi-php.c

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS	2009-11-25 01:36:41 UTC (rev 291284)
+++ php/php-src/branches/PHP_5_2/NEWS	2009-11-25 02:03:02 UTC (rev 291285)
@@ -10,6 +10,8 @@

 - Fixed error_log() to be binary safe when using message_type 3. (Jani)

+- Fixed bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays).
+  (Felipe)
 - Fixed bug #50282 (xmlrpc_encode_request() changes object into array in
   calling function). (Felipe)
 - Fixed bug #50255 (isset() and empty() silently casts array to object).

Added: php/php-src/branches/PHP_5_2/ext/xmlrpc/tests/bug50285.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/xmlrpc/tests/bug50285.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/xmlrpc/tests/bug50285.phpt	2009-11-25 02:03:02 UTC (rev 291285)
@@ -0,0 +1,115 @@
+--TEST--
+Bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)
+--FILE--
+<?php
+
+function test1($func, $params) {
+    return array(1=>'One', 3=>'Three', 5=>'Five');
+}
+
+function test2($func, $params) {
+    return array('One', 'Three', 'Five', 5);
+}
+
+function test3($func, $params) {
+    return array('One', 3 => 'Three', b'Five' => 5, 'Six');
+}
+
+function test4($func, $params) {
+    return array('One', 'Three', 'Five', b'Six' => 6);
+}
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test1', 'test1');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test1</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test2', 'test2');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test2</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test3', 'test3');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test3</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test4', 'test4');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test4</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+?>
+--EXPECT--
+array(3) {
+  [1]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  [5]=>
+  string(4) "Five"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  [3]=>
+  int(5)
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  ["Five"]=>
+  int(5)
+  [4]=>
+  string(3) "Six"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  ["Six"]=>
+  int(6)
+}


Property changes on: php/php-src/branches/PHP_5_2/ext/xmlrpc/tests/bug50285.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/branches/PHP_5_2/ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 01:36:41 UTC (rev 291284)
+++ php/php-src/branches/PHP_5_2/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 02:03:02 UTC (rev 291285)
@@ -428,7 +428,7 @@
 static XMLRPC_VECTOR_TYPE determine_vector_type (HashTable *ht)
 {
 	int bArray = 0, bStruct = 0, bMixed = 0;
-	unsigned long num_index;
+	unsigned long num_index, last_num = 0;
 	char* my_key;

 	zend_hash_internal_pointer_reset(ht);
@@ -438,8 +438,12 @@
 			if(bStruct) {
 				bMixed = 1;
 				break;
+			} else if (last_num > 0 && last_num != num_index-1) {
+				bStruct = 1;
+				break;
 			}
 			bArray = 1;
+			last_num = num_index;
 		}
 		else if(res == HASH_KEY_NON_EXISTANT) {
 			break;
@@ -500,6 +504,7 @@
 					char* my_key;
 					HashTable *ht = NULL;
 					zval *val_arr;
+					XMLRPC_VECTOR_TYPE vtype;

 					ht = HASH_OF(val);
 					if (ht && ht->nApplyCount > 1) {
@@ -512,7 +517,9 @@
 					zval_copy_ctor(val_arr);
 					INIT_PZVAL(val_arr);
 					convert_to_array(val_arr);
-					xReturn = XMLRPC_CreateVector(key, determine_vector_type(Z_ARRVAL_P(val_arr)));
+
+					vtype = determine_vector_type(Z_ARRVAL_P(val_arr));
+					xReturn = XMLRPC_CreateVector(key, vtype);

 					zend_hash_internal_pointer_reset(Z_ARRVAL_P(val_arr));
 					while(zend_hash_get_current_data(Z_ARRVAL_P(val_arr), (void**)&pIter) == SUCCESS) {
@@ -528,7 +535,15 @@
 									ht->nApplyCount++;
 								}
 								if (res == HASH_KEY_IS_LONG) {
-									XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(0, *pIter, depth++ TSRMLS_CC));
+									char *num_str = NULL;
+
+									if (vtype != xmlrpc_vector_array) {
+										spprintf(&num_str, 0, "%ld", num_index);
+									}
+									XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(num_str, *pIter, depth++ TSRMLS_CC));
+									if (num_str) {
+										efree(num_str);
+									}
 								} else {
 									XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(my_key, *pIter, depth++ TSRMLS_CC));
 								}

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2009-11-25 01:36:41 UTC (rev 291284)
+++ php/php-src/branches/PHP_5_3/NEWS	2009-11-25 02:03:02 UTC (rev 291285)
@@ -26,6 +26,8 @@
 - Fixed memory leak in extension loading when an error occurs on Windows.
   (Pierre)

+- Fixed bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays).
+  (Felipe)
 - Fixed bug #50282 (xmlrpc_encode_request() changes object into array in
   calling function). (Felipe)
 - Fixed bug #50267 (get_browser(null) does not use HTTP_USER_AGENT). (Jani)

Added: php/php-src/branches/PHP_5_3/ext/xmlrpc/tests/bug50285.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/xmlrpc/tests/bug50285.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/xmlrpc/tests/bug50285.phpt	2009-11-25 02:03:02 UTC (rev 291285)
@@ -0,0 +1,115 @@
+--TEST--
+Bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)
+--FILE--
+<?php
+
+function test1($func, $params) {
+    return array(1=>'One', 3=>'Three', 5=>'Five');
+}
+
+function test2($func, $params) {
+    return array('One', 'Three', 'Five', 5);
+}
+
+function test3($func, $params) {
+    return array('One', 3 => 'Three', b'Five' => 5, 'Six');
+}
+
+function test4($func, $params) {
+    return array('One', 'Three', 'Five', b'Six' => 6);
+}
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test1', 'test1');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test1</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test2', 'test2');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test2</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test3', 'test3');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test3</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test4', 'test4');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test4</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+?>
+--EXPECT--
+array(3) {
+  [1]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  [5]=>
+  string(4) "Five"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  [3]=>
+  int(5)
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  ["Five"]=>
+  int(5)
+  [4]=>
+  string(3) "Six"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  ["Six"]=>
+  int(6)
+}


Property changes on: php/php-src/branches/PHP_5_3/ext/xmlrpc/tests/bug50285.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/branches/PHP_5_3/ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 01:36:41 UTC (rev 291284)
+++ php/php-src/branches/PHP_5_3/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 02:03:02 UTC (rev 291285)
@@ -484,7 +484,7 @@
 static XMLRPC_VECTOR_TYPE determine_vector_type (HashTable *ht)
 {
 	int bArray = 0, bStruct = 0, bMixed = 0;
-	unsigned long num_index;
+	unsigned long num_index, last_num = 0;
 	char* my_key;

 	zend_hash_internal_pointer_reset(ht);
@@ -495,8 +495,12 @@
 			if (bStruct) {
 				bMixed = 1;
 				break;
+			} else if (last_num > 0 && last_num != num_index-1) {
+				bStruct = 1;
+				break;
 			}
 			bArray = 1;
+			last_num = num_index;
 		} else if (res == HASH_KEY_NON_EXISTANT) {
 			break;
 		} else if (res == HASH_KEY_IS_STRING) {
@@ -557,6 +561,7 @@
 						char* my_key;
 						HashTable *ht = NULL;
 						zval *val_arr;
+						XMLRPC_VECTOR_TYPE vtype;

 						ht = HASH_OF(val);
 						if (ht && ht->nApplyCount > 1) {
@@ -570,7 +575,8 @@
 						INIT_PZVAL(val_arr);
 						convert_to_array(val_arr);

-						xReturn = XMLRPC_CreateVector(key, determine_vector_type(Z_ARRVAL_P(val_arr)));
+						vtype = determine_vector_type(Z_ARRVAL_P(val_arr));
+						xReturn = XMLRPC_CreateVector(key, vtype);

 						zend_hash_internal_pointer_reset(Z_ARRVAL_P(val_arr));
 						while(zend_hash_get_current_data(Z_ARRVAL_P(val_arr), (void**)&pIter) == SUCCESS) {
@@ -586,7 +592,15 @@
 										ht->nApplyCount++;
 									}
 									if (res == HASH_KEY_IS_LONG) {
-										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(0, *pIter, depth++ TSRMLS_CC));
+										char *num_str = NULL;
+
+										if (vtype != xmlrpc_vector_array) {
+											spprintf(&num_str, 0, "%ld", num_index);
+										}
+										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(num_str, *pIter, depth++ TSRMLS_CC));
+										if (num_str) {
+											efree(num_str);
+										}
 									} else {
 										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(my_key, *pIter, depth++ TSRMLS_CC));
 									}

Added: php/php-src/trunk/ext/xmlrpc/tests/bug50285.phpt
===================================================================
--- php/php-src/trunk/ext/xmlrpc/tests/bug50285.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/xmlrpc/tests/bug50285.phpt	2009-11-25 02:03:02 UTC (rev 291285)
@@ -0,0 +1,115 @@
+--TEST--
+Bug #50285 (xmlrpc does not preserve keys in encoded indexed arrays)
+--FILE--
+<?php
+
+function test1($func, $params) {
+    return array(1=>'One', 3=>'Three', 5=>'Five');
+}
+
+function test2($func, $params) {
+    return array('One', 'Three', 'Five', 5);
+}
+
+function test3($func, $params) {
+    return array('One', 3 => 'Three', b'Five' => 5, 'Six');
+}
+
+function test4($func, $params) {
+    return array('One', 'Three', 'Five', b'Six' => 6);
+}
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test1', 'test1');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test1</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test2', 'test2');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test2</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test3', 'test3');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test3</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+// ------------
+
+$server = xmlrpc_server_create();
+$result = xmlrpc_server_register_method($server, 'test4', 'test4');
+$HTTP_RAW_POST_DATA = <<<EOD
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+<methodName>test4</methodName>
+<params />
+</methodCall>
+EOD;
+$response = xmlrpc_server_call_method($server, $HTTP_RAW_POST_DATA, null);
+var_dump(xmlrpc_decode($response));
+
+?>
+--EXPECT--
+array(3) {
+  [1]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  [5]=>
+  string(4) "Five"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  [3]=>
+  int(5)
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [3]=>
+  string(5) "Three"
+  ["Five"]=>
+  int(5)
+  [4]=>
+  string(3) "Six"
+}
+array(4) {
+  [0]=>
+  string(3) "One"
+  [1]=>
+  string(5) "Three"
+  [2]=>
+  string(4) "Five"
+  ["Six"]=>
+  int(6)
+}


Property changes on: php/php-src/trunk/ext/xmlrpc/tests/bug50285.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- php/php-src/trunk/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 01:36:41 UTC (rev 291284)
+++ php/php-src/trunk/ext/xmlrpc/xmlrpc-epi-php.c	2009-11-25 02:03:02 UTC (rev 291285)
@@ -489,7 +489,7 @@
 static XMLRPC_VECTOR_TYPE determine_vector_type (HashTable *ht) /* {{{ */
 {
 	int bArray = 0, bStruct = 0, bMixed = 0;
-	unsigned long num_index;
+	unsigned long num_index, last_num = 0;
 	zstr my_key;

 	zend_hash_internal_pointer_reset(ht);
@@ -499,8 +499,12 @@
 			if (bStruct) {
 				bMixed = 1;
 				break;
+			} else if (last_num > 0 && last_num != num_index-1) {
+				bStruct = 1;
+				break;
 			}
 			bArray = 1;
+			last_num = num_index;
 		} else if (res == HASH_KEY_NON_EXISTANT) {
 			break;
 		} else if (res == HASH_KEY_IS_STRING || res == HASH_KEY_IS_UNICODE) {
@@ -561,6 +565,7 @@
 						zstr my_key;
 						HashTable *ht = NULL;
 						zval *val_arr;
+						XMLRPC_VECTOR_TYPE vtype;

 						ht = HASH_OF(val);
 						if (ht && ht->nApplyCount > 1) {
@@ -573,7 +578,9 @@
 						zval_copy_ctor(val_arr);
 						INIT_PZVAL(val_arr);
 						convert_to_array(val_arr);
-						xReturn = XMLRPC_CreateVector(key, determine_vector_type(Z_ARRVAL_P(val_arr)));
+
+						vtype = determine_vector_type(Z_ARRVAL_P(val_arr));
+						xReturn = XMLRPC_CreateVector(key, vtype);

 						zend_hash_internal_pointer_reset(Z_ARRVAL_P(val_arr));
 						while (zend_hash_get_current_data(Z_ARRVAL_P(val_arr), (void**)&pIter) == SUCCESS) {
@@ -588,7 +595,15 @@
 										ht->nApplyCount++;
 									}
 									if (res == HASH_KEY_IS_LONG) {
-										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(0, *pIter, depth++ TSRMLS_CC));
+										char *num_str = NULL;
+
+										if (vtype != xmlrpc_vector_array) {
+											spprintf(&num_str, 0, "%ld", num_index);
+										}
+										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(num_str, *pIter, depth++ TSRMLS_CC));
+										if (num_str) {
+											efree(num_str);
+										}
 									} else {
 										XMLRPC_AddValueToVector(xReturn, PHP_to_XMLRPC_worker(my_key.s, *pIter, depth++ TSRMLS_CC));
 									}
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to