Skip to content

Commit e0b72d2

Browse files
author
Ilia Alshanetsky
committed
Improve handling of POST data with Andrei's help.
1 parent 9901e4a commit e0b72d2

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

ext/curl/interface.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,22 +1451,36 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
14511451
UErrorCode status = U_ZERO_ERROR;
14521452
uint data_len;
14531453

1454-
SEPARATE_ZVAL(current);
1455-
1456-
if (Z_TYPE_PP(current) == IS_UNICODE) {
1457-
zend_unicode_to_string_ex(UG(utf8_conv), &postval, &data_len, Z_USTRVAL_PP(current), Z_USTRLEN_PP(current), &status);
1458-
} else {
1459-
convert_to_string_ex(current);
1460-
postval = Z_STRVAL_PP(current);
1461-
data_len = Z_STRLEN_PP(current);
1454+
switch (Z_TYPE_PP(current)) {
1455+
case IS_UNICODE:
1456+
ntype = HASH_KEY_IS_UNICODE;
1457+
break;
1458+
case IS_STRING:
1459+
ntype = HASH_KEY_IS_STRING;
1460+
break;
1461+
default:
1462+
if (type != -1) {
1463+
ntype = type;
1464+
} else {
1465+
ntype = HASH_KEY_IS_STRING;
1466+
}
1467+
break;
14621468
}
14631469

1464-
zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
1465-
1466-
ntype = zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
14671470
if (type == -1) {
14681471
type = ntype;
14691472
} else if (type != ntype) {
1473+
goto type_conflict;
1474+
}
1475+
1476+
SEPARATE_ZVAL(current);
1477+
convert_to_string_with_converter_ex(current, UG(utf8_conv));
1478+
postval = Z_STRVAL_PP(current);
1479+
data_len = Z_STRLEN_PP(current);
1480+
1481+
ntype = zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
1482+
if (type != ntype && ntype != HASH_KEY_IS_LONG) {
1483+
type_conflict:
14701484
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Form parameters must either be all unicode or all binary");
14711485
continue;
14721486
}

0 commit comments

Comments
 (0)