From: Michael Wallner Date: Sat, 8 Jul 2006 16:31:47 +0000 (+0000) Subject: - fix HttpQueryString failures with objects as argument X-Git-Tag: RELEASE_1_1_0~6 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d309416dd166624d97ee795bd87ee5b06714f932;p=m6w6%2Fext-http - fix HttpQueryString failures with objects as argument --- diff --git a/http_querystring_api.c b/http_querystring_api.c index 76af348..4c45664 100644 --- a/http_querystring_api.c +++ b/http_querystring_api.c @@ -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(¶ms_entry); + } if (key_type == HASH_KEY_IS_STRING) { add_assoc_zval_ex(qarray, key, keylen, params_entry); } else { diff --git a/http_querystring_object.c b/http_querystring_object.c index 33e4356..c6a1bdb 100644 --- a/http_querystring_object.c +++ b/http_querystring_object.c @@ -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); diff --git a/http_url_api.c b/http_url_api.c index 60fc11f..fb7f0ae 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -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); diff --git a/package2.xml b/package2.xml index 2a1c73b..cd98b98 100644 --- a/package2.xml +++ b/package2.xml @@ -40,6 +40,7 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised --FILE-- --FILE-- +--FILE-- + (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