From: Michael Wallner Date: Fri, 16 Aug 2019 12:02:13 +0000 (+0200) Subject: addendum to #92 X-Git-Tag: RELEASE_3_2_2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=19b4a9cd20fd1cdf5f896b21a2e7b0e3d177ebe3;p=m6w6%2Fext-http addendum to #92 ignore numeric array keys for file entries --- diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index f0068b8..db86ab0 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -392,14 +392,17 @@ static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const ZEND_HASH_FOREACH_KEY_VAL_IND(files, key.h, key.key, val) { if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) { - char *str = format_key(&key, name); + char *str = key.key ? format_key(&key, name) : NULL; + const char *prefix = str ?: name; - if (SUCCESS != add_recursive_files(body, str, HASH_OF(val))) { + if (SUCCESS != add_recursive_files(body, prefix, HASH_OF(val))) { efree(str); HT_UNPROTECT_RECURSION(files); return FAILURE; } - efree(str); + if (str) { + efree(str); + } } } ZEND_HASH_FOREACH_END(); diff --git a/tests/gh-issue92.phpt b/tests/gh-issue92.phpt new file mode 100644 index 0000000..eb604c8 --- /dev/null +++ b/tests/gh-issue92.phpt @@ -0,0 +1,165 @@ +--TEST-- +gh-issue #93: message body add form ignores numeric indices +--SKIPIF-- + +--FILE-- +addForm( + array("foo", "bar", "baz"), + array( + array( + "file" => __FILE__, + "name" => "upload", + "type" => "text/plain", + ), + "dir" => array( + array( + "file" => __FILE__, + "name" => 1, + "type" => "text/plain", + ), + array( + "file" => __FILE__, + "name" => 2, + "type" => "text/plain", + ), + ), + ) +); + +echo $temp; + +?> +DONE +--EXPECTF-- +Test +--%x.%x +Content-Disposition: form-data; name="0" + +foo +--%x.%x +Content-Disposition: form-data; name="1" + +bar +--%x.%x +Content-Disposition: form-data; name="2" + +baz +--%x.%x +Content-Disposition: form-data; name="upload"; filename="gh-issue92.php" +Content-Transfer-Encoding: binary +Content-Type: text/plain + +addForm( + array("foo", "bar", "baz"), + array( + array( + "file" => __FILE__, + "name" => "upload", + "type" => "text/plain", + ), + "dir" => array( + array( + "file" => __FILE__, + "name" => 1, + "type" => "text/plain", + ), + array( + "file" => __FILE__, + "name" => 2, + "type" => "text/plain", + ), + ), + ) +); + +echo $temp; + +?> +DONE + +--%x.%x +Content-Disposition: form-data; name="dir[1]"; filename="gh-issue92.php" +Content-Transfer-Encoding: binary +Content-Type: text/plain + +addForm( + array("foo", "bar", "baz"), + array( + array( + "file" => __FILE__, + "name" => "upload", + "type" => "text/plain", + ), + "dir" => array( + array( + "file" => __FILE__, + "name" => 1, + "type" => "text/plain", + ), + array( + "file" => __FILE__, + "name" => 2, + "type" => "text/plain", + ), + ), + ) +); + +echo $temp; + +?> +DONE + +--%x.%x +Content-Disposition: form-data; name="dir[2]"; filename="gh-issue92.php" +Content-Transfer-Encoding: binary +Content-Type: text/plain + +addForm( + array("foo", "bar", "baz"), + array( + array( + "file" => __FILE__, + "name" => "upload", + "type" => "text/plain", + ), + "dir" => array( + array( + "file" => __FILE__, + "name" => 1, + "type" => "text/plain", + ), + array( + "file" => __FILE__, + "name" => 2, + "type" => "text/plain", + ), + ), + ) +); + +echo $temp; + +?> +DONE + +--%x.%x-- +DONE