Merge branch 'v2.6.x'
[m6w6/ext-http] / src / php_http_params.c
index b51ab712657cab9e0fff62a8ca3d7ee982f2151c..92cc558962af525355cfa0fc32672dd858e8e3a5 100644 (file)
@@ -248,16 +248,18 @@ static inline void sanitize_key(unsigned flags, const char *str, size_t len, zva
        if (flags & PHP_HTTP_PARAMS_ESCAPED) {
                sanitize_escaped(zv);
        }
-       
+
        if (!Z_STRLEN_P(zv)) {
                return;
        }
 
-       eos = &Z_STRVAL_P(zv)[Z_STRLEN_P(zv)-1];
-       if (*eos == '*') {
-               *eos = '\0';
-               *rfc5987 = 1;
-               Z_STRLEN_P(zv) -= 1;
+       if (flags & PHP_HTTP_PARAMS_RFC5987) {
+               eos = &Z_STRVAL_P(zv)[Z_STRLEN_P(zv)-1];
+               if (*eos == '*') {
+                       *eos = '\0';
+                       *rfc5987 = 1;
+                       Z_STRLEN_P(zv) -= 1;
+               }
        }
 
        if (flags & PHP_HTTP_PARAMS_URLENCODED) {
@@ -487,7 +489,7 @@ static void merge_param(HashTable *params, zval *zdata, zval **current_param, zv
                        zval *test_ptr;
 
                        while (Z_TYPE_P(zdata_ptr) == IS_ARRAY && (test_ptr = zend_hash_get_current_data(Z_ARRVAL_P(zdata_ptr)))) {
-                               if (Z_TYPE_P(test_ptr) == IS_ARRAY) {
+                               if (Z_TYPE_P(test_ptr) == IS_ARRAY && Z_TYPE_P(ptr) == IS_ARRAY) {
                                        zval *tmp_ptr = ptr;
 
                                        /* now find key in ptr */
@@ -552,8 +554,12 @@ static void merge_param(HashTable *params, zval *zdata, zval **current_param, zv
 static void push_param(HashTable *params, php_http_params_state_t *state, const php_http_params_opts_t *opts)
 {
        if (state->val.str) {
-               if (0 < (state->val.len = state->input.str - state->val.str)) {
+               if (!state->current.val) {
+                       return;
+               } else if (0 < (state->val.len = state->input.str - state->val.str)) {
                        sanitize_value(opts->flags, state->val.str, state->val.len, state->current.val, state->rfc5987);
+               } else {
+                       ZVAL_EMPTY_STRING(state->current.val);
                }
                state->rfc5987 = 0;
        } else if (state->arg.str) {
@@ -635,7 +641,7 @@ static size_t check_sep(php_http_params_state_t *state, php_http_params_token_t
        if (state->quotes || state->escape) {
                return 0;
        }
-       
+
        if (sep) while (*sep) {
                if (check_str(state->input.str, state->input.len, (*sep)->str, (*sep)->len)) {
                        return (*sep)->len;
@@ -685,7 +691,7 @@ HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t
                } else {
                        state.escape = (*state.input.str == '\\');
                }
-               
+
                if (!state.param.str) {
                        /* initialize */
                        skip_sep(0, &state, opts->param, opts->arg, opts->val);
@@ -739,7 +745,7 @@ HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t
                                }
                        }
                }
-               
+
                if (state.input.len) {
                        ++state.input.str;
                        --state.input.len;
@@ -1027,6 +1033,12 @@ void php_http_params_separator_free(php_http_params_token_t **separator)
        }
 }
 
+static zend_class_entry *php_http_params_class_entry;
+zend_class_entry *php_http_params_get_class_entry(void)
+{
+       return php_http_params_class_entry;
+}
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams___construct, 0, 0, 0)
        ZEND_ARG_INFO(0, params)
        ZEND_ARG_INFO(0, param_sep)
@@ -1043,7 +1055,7 @@ PHP_METHOD(HttpParams, __construct)
 
        php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!/z/z/z/l", &zparams, &param_sep, &arg_sep, &val_sep, &flags), invalid_arg, return);
 
-       zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh);
+       zend_replace_error_handling(EH_THROW, php_http_get_exception_runtime_class_entry(), &zeh);
        {
                switch (ZEND_NUM_ARGS()) {
                        case 5:
@@ -1283,8 +1295,6 @@ static zend_function_entry php_http_params_methods[] = {
        EMPTY_FUNCTION_ENTRY
 };
 
-zend_class_entry *php_http_params_class_entry;
-
 PHP_MINIT_FUNCTION(http_params)
 {
        zend_class_entry ce = {0};