|
20 | 20 | #include "SAPI.h" |
21 | 21 | #include "zend_exceptions.h" |
22 | 22 | #include "basic_functions.h" |
| 23 | +#include "zend_enum.h" |
23 | 24 |
|
24 | 25 | static void php_url_encode_scalar(zval *scalar, smart_str *form_str, |
25 | 26 | int encoding_type, zend_ulong index_int, |
@@ -56,6 +57,7 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str, |
56 | 57 | } |
57 | 58 | smart_str_appendc(form_str, '='); |
58 | 59 |
|
| 60 | +try_again: |
59 | 61 | switch (Z_TYPE_P(scalar)) { |
60 | 62 | case IS_STRING: { |
61 | 63 | zend_string *encoded_data; |
@@ -90,6 +92,14 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str, |
90 | 92 | case IS_TRUE: |
91 | 93 | smart_str_appendc(form_str, '1'); |
92 | 94 | break; |
| 95 | + case IS_OBJECT: |
| 96 | + ZEND_ASSERT(Z_OBJCE_P(scalar)->ce_flags & ZEND_ACC_ENUM); |
| 97 | + if (Z_OBJCE_P(scalar)->enum_backing_type == IS_UNDEF) { |
| 98 | + zend_value_error("Unbacked enum %s cannot be converted to a string", ZSTR_VAL(Z_OBJCE_P(scalar)->name)); |
| 99 | + return; |
| 100 | + } |
| 101 | + scalar = zend_enum_fetch_case_value(Z_OBJ_P(scalar)); |
| 102 | + goto try_again; |
93 | 103 | /* All possible types are either handled here or previously */ |
94 | 104 | EMPTY_SWITCH_DEFAULT_CASE(); |
95 | 105 | } |
@@ -154,7 +164,9 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, |
154 | 164 | } |
155 | 165 |
|
156 | 166 | ZVAL_DEREF(zdata); |
157 | | - if (Z_TYPE_P(zdata) == IS_ARRAY || Z_TYPE_P(zdata) == IS_OBJECT) { |
| 167 | + if (Z_TYPE_P(zdata) == IS_ARRAY |
| 168 | + || (Z_TYPE_P(zdata) == IS_OBJECT |
| 169 | + && !(Z_OBJCE_P(zdata)->ce_flags & ZEND_ACC_ENUM))) { |
158 | 170 | zend_string *new_prefix; |
159 | 171 | if (key) { |
160 | 172 | zend_string *encoded_key; |
@@ -233,6 +245,11 @@ PHP_FUNCTION(http_build_query) |
233 | 245 | Z_PARAM_LONG(enc_type) |
234 | 246 | ZEND_PARSE_PARAMETERS_END(); |
235 | 247 |
|
| 248 | + if (UNEXPECTED(Z_TYPE_P(formdata) == IS_OBJECT && (Z_OBJCE_P(formdata)->ce_flags & ZEND_ACC_ENUM))) { |
| 249 | + zend_argument_type_error(1, "must be of type array, %s given", zend_zval_value_name(formdata)); |
| 250 | + RETURN_THROWS(); |
| 251 | + } |
| 252 | + |
236 | 253 | php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, /* key_prefix */ NULL, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type); |
237 | 254 |
|
238 | 255 | RETURN_STR(smart_str_extract(&formstr)); |
|
0 commit comments