mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Drop key_suffix parameter in php_url_encode_hash_ex()
The suffix was always constant and the same value between calls and depends on a prefix being needed
This commit is contained in:
@@ -23,7 +23,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
|
||||
const char *index_string, size_t index_string_len,
|
||||
const char *num_prefix, size_t num_prefix_len,
|
||||
const zend_string *key_prefix,
|
||||
const char *key_suffix, size_t key_suffix_len,
|
||||
const zend_string *arg_sep)
|
||||
{
|
||||
if (form_str->s) {
|
||||
@@ -49,8 +48,8 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
|
||||
}
|
||||
smart_str_append_long(form_str, index_int);
|
||||
}
|
||||
if (key_suffix) {
|
||||
smart_str_appendl(form_str, key_suffix, key_suffix_len);
|
||||
if (key_prefix) {
|
||||
smart_str_appendl(form_str, "%5D", strlen("%5D"));
|
||||
}
|
||||
smart_str_appendc(form_str, '=');
|
||||
|
||||
@@ -97,7 +96,6 @@ static void php_url_encode_scalar(zval *scalar, smart_str *form_str,
|
||||
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
const char *num_prefix, size_t num_prefix_len,
|
||||
const zend_string *key_prefix,
|
||||
const char *key_suffix, size_t key_suffix_len,
|
||||
zval *type, const zend_string *arg_sep, int enc_type)
|
||||
{
|
||||
zend_string *key = NULL;
|
||||
@@ -164,15 +162,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
}
|
||||
|
||||
if (key_prefix) {
|
||||
/* zend_string_concat4() */
|
||||
size_t len = ZSTR_LEN(key_prefix) + ZSTR_LEN(encoded_key) + key_suffix_len + strlen("%5B");
|
||||
new_prefix = zend_string_alloc(len, 0);
|
||||
|
||||
memcpy(ZSTR_VAL(new_prefix), ZSTR_VAL(key_prefix), ZSTR_LEN(key_prefix));
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix), ZSTR_VAL(encoded_key), ZSTR_LEN(encoded_key));
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + ZSTR_LEN(encoded_key), key_suffix, key_suffix_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + ZSTR_LEN(encoded_key) + key_suffix_len, "%5B", strlen("%5B"));
|
||||
ZSTR_VAL(new_prefix)[len] = '\0';
|
||||
new_prefix = zend_string_concat3(ZSTR_VAL(key_prefix), ZSTR_LEN(key_prefix), ZSTR_VAL(encoded_key), ZSTR_LEN(encoded_key), "%5D%5B", strlen("%5D%5B"));
|
||||
} else {
|
||||
new_prefix = zend_string_concat2(ZSTR_VAL(encoded_key), ZSTR_LEN(encoded_key), "%5B", strlen("%5B"));
|
||||
}
|
||||
@@ -184,26 +174,17 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
index_int_as_str_len = spprintf(&index_int_as_str, 0, ZEND_LONG_FMT, idx);
|
||||
|
||||
if (key_prefix && num_prefix) {
|
||||
/* zend_string_concat5() */
|
||||
size_t len = ZSTR_LEN(key_prefix) + num_prefix_len + index_int_as_str_len + key_suffix_len + strlen("%5B");
|
||||
/* zend_string_concat4() */
|
||||
size_t len = ZSTR_LEN(key_prefix) + num_prefix_len + index_int_as_str_len + strlen("%5D%5B");
|
||||
new_prefix = zend_string_alloc(len, 0);
|
||||
|
||||
memcpy(ZSTR_VAL(new_prefix), ZSTR_VAL(key_prefix), ZSTR_LEN(key_prefix));
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix), num_prefix, num_prefix_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + num_prefix_len, index_int_as_str, index_int_as_str_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + num_prefix_len +index_int_as_str_len, key_suffix, key_suffix_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + num_prefix_len +index_int_as_str_len + key_suffix_len, "%5B", strlen("%5B"));
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + num_prefix_len +index_int_as_str_len, "%5D%5B", strlen("%5D%5B"));
|
||||
ZSTR_VAL(new_prefix)[len] = '\0';
|
||||
} else if (key_prefix) {
|
||||
/* zend_string_concat4() */
|
||||
size_t len = ZSTR_LEN(key_prefix) + index_int_as_str_len + key_suffix_len + strlen("%5B");
|
||||
new_prefix = zend_string_alloc(len, 0);
|
||||
|
||||
memcpy(ZSTR_VAL(new_prefix), ZSTR_VAL(key_prefix), ZSTR_LEN(key_prefix));
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix), index_int_as_str, index_int_as_str_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + index_int_as_str_len, key_suffix, key_suffix_len);
|
||||
memcpy(ZSTR_VAL(new_prefix) + ZSTR_LEN(key_prefix) + index_int_as_str_len + key_suffix_len, "%5B", strlen("%5B"));
|
||||
ZSTR_VAL(new_prefix)[len] = '\0';
|
||||
new_prefix = zend_string_concat3(ZSTR_VAL(key_prefix), ZSTR_LEN(key_prefix), index_int_as_str, index_int_as_str_len, "%5D%5B", strlen("%5D%5B"));
|
||||
} else if (num_prefix) {
|
||||
new_prefix = zend_string_concat3(num_prefix, num_prefix_len, index_int_as_str, index_int_as_str_len, "%5B", strlen("%5B"));
|
||||
} else {
|
||||
@@ -212,7 +193,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
efree(index_int_as_str);
|
||||
}
|
||||
GC_TRY_PROTECT_RECURSION(ht);
|
||||
php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, new_prefix, "%5D", 3, (Z_TYPE_P(zdata) == IS_OBJECT ? zdata : NULL), arg_sep, enc_type);
|
||||
php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, new_prefix, (Z_TYPE_P(zdata) == IS_OBJECT ? zdata : NULL), arg_sep, enc_type);
|
||||
GC_TRY_UNPROTECT_RECURSION(ht);
|
||||
zend_string_release_ex(new_prefix, false);
|
||||
} else if (Z_TYPE_P(zdata) == IS_NULL || Z_TYPE_P(zdata) == IS_RESOURCE) {
|
||||
@@ -224,7 +205,6 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
prop_name, prop_len,
|
||||
num_prefix, num_prefix_len,
|
||||
key_prefix,
|
||||
key_suffix, key_suffix_len,
|
||||
arg_sep);
|
||||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
@@ -250,7 +230,7 @@ PHP_FUNCTION(http_build_query)
|
||||
Z_PARAM_LONG(enc_type)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, /* key_prefix */ NULL, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type);
|
||||
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);
|
||||
|
||||
RETURN_STR(smart_str_extract(&formstr));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
||||
const char *num_prefix, size_t num_prefix_len,
|
||||
const zend_string *key_prefix,
|
||||
const char *key_suffix, size_t key_suffix_len,
|
||||
zval *type, const zend_string *arg_sep, int enc_type);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user