allow arguments at first level, i.e. the following examples are equally stringified...
authorMichael Wallner <mike@php.net>
Tue, 20 Mar 2012 20:55:07 +0000 (20:55 +0000)
committerMichael Wallner <mike@php.net>
Tue, 20 Mar 2012 20:55:07 +0000 (20:55 +0000)
["key"=>["value"=>true,"arguments"=>["some"=>"stuff"]]]
["key"=>["value"=>true,"some"=>"stuff"]]
["key"=>["some"=>"stuff"]]

php_http_params.c

index a07e50ba402962cd3bff5843a548c10d28a87cf0..f3617527bc023896258f5c51b262b8948886586d 100644 (file)
@@ -223,39 +223,46 @@ PHP_HTTP_API php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf
                                }
                        }
                        /* add arguments */
-                       if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("arguments"), (void *) &zargs)) {
-                               if (Z_TYPE_PP(zargs) == IS_ARRAY) {
-                                       FOREACH_KEYVAL(pos2, *zargs, key2, zarg) {
-                                               /* new arg? */
-                                               if (PHP_HTTP_BUFFER_LEN(buf)) {
-                                                       php_http_buffer_append(buf, ass, asl);
-                                               }
+                       if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(zparam), ZEND_STRS("arguments"), (void *) &zargs)) {
+                               zargs = zparam;
+                       }
+
+                       if (Z_TYPE_PP(zargs) == IS_ARRAY) {
+                               FOREACH_KEYVAL(pos2, *zargs, key2, zarg) {
+                                       /* skip "value" if zargs == zparam */
+                                       if (zargs == zparam && key2.type == HASH_KEY_IS_STRING && !strcmp(key2.str, "value")) {
+                                               continue;
+                                       }
 
-                                               /* add name */
-                                               if (key2.type == HASH_KEY_IS_STRING) {
-                                                       php_http_buffer_append(buf, key2.str, key2.len - 1);
+                                       /* new arg? */
+                                       if (PHP_HTTP_BUFFER_LEN(buf)) {
+                                               php_http_buffer_append(buf, ass, asl);
+                                       }
+
+                                       /* add name */
+                                       if (key2.type == HASH_KEY_IS_STRING) {
+                                               php_http_buffer_append(buf, key2.str, key2.len - 1);
+                                       } else {
+                                               php_http_buffer_appendf(buf, "%lu", key2.num);
+                                       }
+                                       /* add value */
+                                       if (Z_TYPE_PP(zarg) != IS_BOOL) {
+                                               zval *tmp = php_http_ztyp(IS_STRING, *zarg);
+                                               int escaped_len;
+
+                                               Z_STRVAL_P(tmp) = php_addslashes(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &escaped_len, 1 TSRMLS_CC);
+                                               php_http_buffer_append(buf, vss, vsl);
+                                               if (escaped_len != Z_STRLEN_P(tmp)) {
+                                                       php_http_buffer_appends(buf, "\"");
+                                                       php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) = escaped_len);
+                                                       php_http_buffer_appends(buf, "\"");
                                                } else {
-                                                       php_http_buffer_appendf(buf, "%lu", key2.num);
-                                               }
-                                               /* add value */
-                                               if (Z_TYPE_PP(zarg) != IS_BOOL) {
-                                                       zval *tmp = php_http_ztyp(IS_STRING, *zarg);
-                                                       int escaped_len;
-
-                                                       Z_STRVAL_P(tmp) = php_addslashes(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), &escaped_len, 1 TSRMLS_CC);
-                                                       php_http_buffer_append(buf, vss, vsl);
-                                                       if (escaped_len != Z_STRLEN_P(tmp)) {
-                                                               php_http_buffer_appends(buf, "\"");
-                                                               php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) = escaped_len);
-                                                               php_http_buffer_appends(buf, "\"");
-                                                       } else {
-                                                               php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
-                                                       }
-                                                       zval_ptr_dtor(&tmp);
-                                               } else if (!Z_BVAL_PP(zarg)) {
-                                                       php_http_buffer_append(buf, vss, vsl);
-                                                       php_http_buffer_appends(buf, "0");
+                                                       php_http_buffer_append(buf, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
                                                }
+                                               zval_ptr_dtor(&tmp);
+                                       } else if (!Z_BVAL_PP(zarg)) {
+                                               php_http_buffer_append(buf, vss, vsl);
+                                               php_http_buffer_appends(buf, "0");
                                        }
                                }
                        }