diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2021-01-18 11:01:39 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2021-01-18 11:01:39 +0100 |
commit | d0e3fb495ff77ec0aa8bc052c15a3899e9da7899 (patch) | |
tree | 029723accd58267946bdf475740d5748c9951042 /ext/curl | |
parent | ebca8deaaf3d7518bfe2fb135b331d9901d9134d (diff) | |
parent | c321896a372c3358663f2f1e8721c61c46634a0c (diff) | |
download | php-git-d0e3fb495ff77ec0aa8bc052c15a3899e9da7899.tar.gz |
Merge branch 'PHP-8.0'
* PHP-8.0:
Fix #80595: Resetting POSTFIELDS to empty array breaks request
Diffstat (limited to 'ext/curl')
-rw-r--r-- | ext/curl/interface.c | 9 | ||||
-rw-r--r-- | ext/curl/tests/bug79033.phpt | 1 | ||||
-rw-r--r-- | ext/curl/tests/bug80595.phpt | 30 |
3 files changed, 39 insertions, 1 deletions
diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 82f512d29d..1044031a88 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2695,7 +2695,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i case CURLOPT_POSTFIELDS: if (Z_TYPE_P(zvalue) == IS_ARRAY) { - return build_mime_structure_from_hash(ch, zvalue); + if (zend_hash_num_elements(HASH_OF(zvalue)) == 0) { + /* no need to build the mime structure for empty hashtables; + also works around https://github.com/curl/curl/issues/6455 */ + curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, ""); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, 0); + } else { + return build_mime_structure_from_hash(ch, zvalue); + } } else { zend_string *tmp_str; zend_string *str = zval_get_tmp_string(zvalue, &tmp_str); diff --git a/ext/curl/tests/bug79033.phpt b/ext/curl/tests/bug79033.phpt index c70611dda6..1ba75ad0e6 100644 --- a/ext/curl/tests/bug79033.phpt +++ b/ext/curl/tests/bug79033.phpt @@ -25,5 +25,6 @@ string(%d) "POST /get.inc?test=post HTTP/1.1 Host: localhost:%d Accept: */* Content-Length: 0 +Content-Type: application/x-www-form-urlencoded " diff --git a/ext/curl/tests/bug80595.phpt b/ext/curl/tests/bug80595.phpt new file mode 100644 index 0000000000..48137db4e6 --- /dev/null +++ b/ext/curl/tests/bug80595.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #80595 (Resetting POSTFIELDS to empty array breaks request) +--SKIPIF-- +<?php include 'skipif.inc'; ?> +--FILE-- +<?php +include 'server.inc'; +$host = curl_cli_server_start(); +$ch = curl_init(); +curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_URL => "{$host}/get.inc?test=post", +]); + +curl_setopt($ch, CURLOPT_POSTFIELDS, ['foo' => 'bar']); +var_dump(curl_exec($ch)); + +curl_setopt($ch, CURLOPT_POSTFIELDS, []); +var_dump(curl_exec($ch)); +?> +--EXPECT-- +string(43) "array(1) { + ["foo"]=> + string(3) "bar" +} +" +string(13) "array(0) { +} +" |