Skip to content

Commit d0e3fb4

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #80595: Resetting POSTFIELDS to empty array breaks request
2 parents ebca8de + c321896 commit d0e3fb4

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

ext/curl/interface.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,14 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
26952695

26962696
case CURLOPT_POSTFIELDS:
26972697
if (Z_TYPE_P(zvalue) == IS_ARRAY) {
2698-
return build_mime_structure_from_hash(ch, zvalue);
2698+
if (zend_hash_num_elements(HASH_OF(zvalue)) == 0) {
2699+
/* no need to build the mime structure for empty hashtables;
2700+
also works around https://github.com/curl/curl/issues/6455 */
2701+
curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, "");
2702+
error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, 0);
2703+
} else {
2704+
return build_mime_structure_from_hash(ch, zvalue);
2705+
}
26992706
} else {
27002707
zend_string *tmp_str;
27012708
zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);

ext/curl/tests/bug79033.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ string(%d) "POST /get.inc?test=post HTTP/1.1
2525
Host: localhost:%d
2626
Accept: */*
2727
Content-Length: 0
28+
Content-Type: application/x-www-form-urlencoded
2829

2930
"

ext/curl/tests/bug80595.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #80595 (Resetting POSTFIELDS to empty array breaks request)
3+
--SKIPIF--
4+
<?php include 'skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
$ch = curl_init();
10+
curl_setopt_array($ch, [
11+
CURLOPT_RETURNTRANSFER => true,
12+
CURLOPT_POST => true,
13+
CURLOPT_URL => "{$host}/get.inc?test=post",
14+
]);
15+
16+
curl_setopt($ch, CURLOPT_POSTFIELDS, ['foo' => 'bar']);
17+
var_dump(curl_exec($ch));
18+
19+
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
20+
var_dump(curl_exec($ch));
21+
?>
22+
--EXPECT--
23+
string(43) "array(1) {
24+
["foo"]=>
25+
string(3) "bar"
26+
}
27+
"
28+
string(13) "array(0) {
29+
}
30+
"

0 commit comments

Comments
 (0)