- fix HttpQueryString failures with objects as argument
authorMichael Wallner <mike@php.net>
Sat, 8 Jul 2006 16:31:47 +0000 (16:31 +0000)
committerMichael Wallner <mike@php.net>
Sat, 8 Jul 2006 16:31:47 +0000 (16:31 +0000)
http_querystring_api.c
http_querystring_object.c
http_url_api.c
package2.xml
tests/HttpQueryString_001.phpt
tests/HttpQueryString_002.phpt
tests/HttpQueryString_004.phpt [new file with mode: 0644]

index 76af3482550572d57f5d33748c1706191b5be48b..4c45664b5aacbdcf982a32ef866c67719a2945b5 100644 (file)
@@ -154,7 +154,8 @@ static inline int _http_querystring_modify_array(zval *qarray, zval *params TSRM
        zval **params_entry = NULL;
        
        FOREACH_KEYLENVAL(pos, params, key, keylen, idx, params_entry) {
-               if (http_querystring_modify_array_ex(qarray, key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG, key, keylen, idx, *params_entry)) {
+               /* only public properties */
+               if ((!key || *key) && http_querystring_modify_array_ex(qarray, key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG, key, keylen, idx, *params_entry)) {
                        rv = 1;
                }
                key = NULL;
@@ -182,8 +183,8 @@ static inline int _http_querystring_modify_array_ex(zval *qarray, int key_type,
                zval equal;
                
                /* recursive */
-               if (Z_TYPE_P(params_entry) == IS_ARRAY) {
-                       return http_querystring_modify_array(*qarray_entry, params_entry);
+               if (Z_TYPE_P(params_entry) == IS_ARRAY || Z_TYPE_P(params_entry) == IS_OBJECT) {
+                       return http_querystring_modify(*qarray_entry, params_entry);
                }
                /* equal */
                if ((SUCCESS == is_equal_function(&equal, *qarray_entry, params_entry TSRMLS_CC)) && Z_BVAL(equal)) {
@@ -193,6 +194,9 @@ static inline int _http_querystring_modify_array_ex(zval *qarray, int key_type,
        
        /* add */
        ZVAL_ADDREF(params_entry);
+       if (Z_TYPE_P(params_entry) == IS_OBJECT) {
+               convert_to_array_ex(&params_entry);
+       }
        if (key_type == HASH_KEY_IS_STRING) {
                add_assoc_zval_ex(qarray, key, keylen, params_entry);
        } else {
index 33e4356f947bbd4a31dd12d71e6afa1b614aaf1a..c6a1bdbe93a49fb4df8717502309874a6d51fc11 100644 (file)
@@ -420,7 +420,7 @@ PHP_METHOD(HttpQueryString, mod)
                qarr = GET_PROP_EX(zobj, queryArray);
                qstr = GET_PROP_EX(zobj, queryString);
                
-               array_copy(orig, qarr);
+               http_querystring_modify(qarr, orig);
                http_querystring_modify(qarr, params);
                http_querystring_update(qarr, qstr);
        
index 60fc11ffb19e086b114a64e10f3a471a2f1cdb0e..fb7f0ae74f3581149ea811bb7a27362bf23f0553 100644 (file)
@@ -391,6 +391,10 @@ PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, c
                }
                
                if (key) {
+                       if (!*key) {
+                               /* only public properties */
+                               continue;
+                       }
                        if (len && key[len - 1] == '\0') {
                                --len;
                        }
@@ -416,10 +420,10 @@ PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, c
                        phpstr_fix(&new_prefix);
                }
                
-               if (Z_TYPE_PP(data) == IS_ARRAY) {
+               if (Z_TYPE_PP(data) == IS_ARRAY || Z_TYPE_PP(data) == IS_OBJECT) {
                        STATUS status;
                        ++ht->nApplyCount;
-                       status = http_urlencode_hash_recursive(Z_ARRVAL_PP(data), str, arg_sep, arg_sep_len, PHPSTR_VAL(&new_prefix), PHPSTR_LEN(&new_prefix));
+                       status = http_urlencode_hash_recursive(HASH_OF(*data), str, arg_sep, arg_sep_len, PHPSTR_VAL(&new_prefix), PHPSTR_LEN(&new_prefix));
                        --ht->nApplyCount;
                        if (SUCCESS != status) {
                                phpstr_dtor(&new_prefix);
index 2a1c73b7226bcf8bcd4e831a663cf691fced8129..cd98b98929487f41f5e0628d1344276b25287dfc 100644 (file)
@@ -40,6 +40,7 @@ support. Parallel requests are available for PHP 5 and greater.
  <license>BSD, revised</license>
  <notes><![CDATA[
 * Fixed HttpResponse::capture() failure if buffered output exceeds 40k
+* Fixed HttpQueryString failures with objects as params
 * Added HttpQueryString::mod(array $params) method
 * Added ArrayAccess to interfaces implemented by HttpQueryString
 * Added HttpMessage::getHeader(string $name) method
index 6a9b5c80bfa5487e36c2d7d4a53fd78ae0be8157..ec64eaddbddc13ecaacd1ba159d932276ddf8f66 100644 (file)
@@ -3,7 +3,7 @@ HttpQueryString global
 --SKIPIF--
 <?php
 include 'skip.inc';
-checkver(5);
+checkmin(5.1);
 ?>
 --FILE--
 <?php
index 63d143e88ceb6615f9904766eb5b6fbee4a8bb0e..9968bf6c210054291048a75e3c2c4fb620cf91f1 100644 (file)
@@ -3,7 +3,7 @@ HttpQueryString local
 --SKIPIF--
 <?php
 include 'skip.inc';
-checkver(5);
+checkmin(5);
 ?>
 --FILE--
 <?php
diff --git a/tests/HttpQueryString_004.phpt b/tests/HttpQueryString_004.phpt
new file mode 100644 (file)
index 0000000..cf70e66
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+HttpQueryString w/ objects
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkmin(5);
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+$foo = (object) array("bar" => (object) array("baz" => 1), "\0*\0prop" => "dontshow");
+$foo->bar->baz = 1;
+var_dump($q = new HttpQueryString(false, $foo));
+$foo->bar->baz = 0;
+var_dump($q->mod($foo));
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+object(HttpQueryString)#3 (2) {
+  ["queryArray:private"]=>
+  array(1) {
+    ["bar"]=>
+    array(1) {
+      ["baz"]=>
+      int(1)
+    }
+  }
+  ["queryString:private"]=>
+  string(14) "bar%5Bbaz%5D=1"
+}
+object(HttpQueryString)#4 (2) {
+  ["queryArray:private"]=>
+  array(1) {
+    ["bar"]=>
+    array(1) {
+      ["baz"]=>
+      int(0)
+    }
+  }
+  ["queryString:private"]=>
+  string(14) "bar%5Bbaz%5D=0"
+}
+Done