X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_params.c;h=92cc558962af525355cfa0fc32672dd858e8e3a5;hp=8db5c353bd18c004ecc8bef617431577fafcb526;hb=b3831bc5f19cf32880ea19341c3527f0e9553517;hpb=e57370d1f00da9e12de0917a9f907281ab8e84b5 diff --git a/src/php_http_params.c b/src/php_http_params.c index 8db5c35..92cc558 100644 --- a/src/php_http_params.c +++ b/src/php_http_params.c @@ -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;